00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef flc_lineardict_H
00021 #define flc_lineardict_H
00022
00023 #include <falcon/types.h>
00024 #include <falcon/itemdict.h>
00025 #include <falcon/item.h>
00026 #include <stdlib.h>
00027
00028 #define flc_DICT_GROWTH 16
00029
00030 namespace Falcon {
00031
00032 class LinearDict;
00033 class VMachine;
00034 class Iterator;
00035
00037 class FALCON_DYN_CLASS LinearDictEntry
00038 {
00039 Item m_key;
00040 Item m_value;
00041
00042 public:
00043
00044 LinearDictEntry( const Item &k, const Item &v ):
00045 m_key( k ),
00046 m_value( v )
00047 {}
00048
00049 void key( const Item &v ) { m_key = v; }
00050 const Item &key() const { return m_key; }
00051 const Item &value() const { return m_value; }
00052 Item &key() { return m_key; }
00053 Item &value() { return m_value; }
00054 void value( const Item &v ) { m_value = v; }
00055
00056 friend class LinearDict;
00057 };
00058
00059
00060 class FALCON_DYN_CLASS LinearDict: public ItemDict
00061 {
00062 uint32 m_size;
00063 uint32 m_alloc;
00064 uint32 m_invalidPos;
00065 LinearDictEntry *m_data;
00066 uint32 m_mark;
00067
00068 bool addInternal( uint32 pos, const Item &key, const Item &value );
00069
00077 bool findInternal( const Item &key, uint32 &ret_pos ) const;
00078 bool removeAt( uint32 pos );
00079
00080 public:
00081
00082 LinearDict();
00083 LinearDict( uint32 prealloc );
00084 ~LinearDict();
00085 virtual FalconData *clone() const;
00086 virtual void gcMark( uint32 gen );
00087
00088 virtual uint32 length() const;
00089 virtual Item *find( const Item &key ) const;
00090 virtual bool findIterator( const Item &key, Iterator &iter );
00091
00092 virtual const Item &front() const;
00093 virtual const Item &back() const;
00094 virtual void append( const Item& item );
00095 virtual void prepend( const Item& item );
00096
00097 virtual bool remove( const Item &key );
00098 virtual void put( const Item &key, const Item &value );
00099 virtual void smartInsert( const Iterator &iter, const Item &key, const Item &value );
00100
00101 virtual void merge( const ItemDict &dict );
00102 virtual void clear();
00103 virtual bool empty() const;
00104
00105 uint32 esize( uint32 num ) const { return sizeof( LinearDictEntry ) * num; }
00106
00107 LinearDictEntry *entries() const { return m_data; }
00108 uint32 allocated() const { return m_alloc; }
00109
00110 void length( uint32 size ) { m_size = size; }
00111 void allocated( uint32 size ) { m_alloc = size; }
00112 void entries( LinearDictEntry *d ) { m_data = d; }
00113
00114 LinearDictEntry *elementAt( uint32 pos ) const
00115 {
00116 if ( pos >= length() )
00117 return 0;
00118 return entries() + pos;
00119 }
00120
00121 bool find( const Item &key, uint32 &ret_pos ) const {
00122 return findInternal( key, ret_pos );
00123 }
00124
00125
00126
00127
00128 protected:
00129
00130 virtual void getIterator( Iterator& tgt, bool tail = false ) const;
00131 virtual void copyIterator( Iterator& tgt, const Iterator& source ) const;
00132
00133 virtual void insert( Iterator &iter, const Item &data );
00134 virtual void erase( Iterator &iter );
00135 virtual bool hasNext( const Iterator &iter ) const;
00136 virtual bool hasPrev( const Iterator &iter ) const;
00137 virtual bool hasCurrent( const Iterator &iter ) const;
00138 virtual bool next( Iterator &iter ) const;
00139 virtual bool prev( Iterator &iter ) const;
00140 virtual Item& getCurrent( const Iterator &iter );
00141 virtual Item& getCurrentKey( const Iterator &iter );
00142 virtual bool equalIterator( const Iterator &first, const Iterator &second ) const;
00143 virtual bool onCriterion( Iterator* elem ) const;
00144 };
00145
00146 }
00147
00148 #endif
00149
00150