00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef USE_VALUE_CACHE
00026
00027 #include "ValueCache.h"
00028
00029 #else
00030
00031 namespace eyedb {
00032
00033 class CollItem {
00034
00035 public:
00036 CollItem(Collection *_coll, const Oid&, Collection::ItemId, int);
00037 CollItem(Collection *_coll, const Object *, Collection::ItemId, int);
00038 CollItem(Collection *_coll, const Value &, Collection::ItemId, int);
00039 CollItem(Collection *_coll, Data, Collection::ItemId, int);
00040
00041 void setState(int _state);
00042 int getState() const {return state;}
00043
00044 void setId(Collection::ItemId _id) {id = _id;}
00045 Collection::ItemId getId() const {return id;}
00046
00047 void setOid(const Oid&);
00048 const Oid& getOid() const;
00049
00050 void setObject(const Object *);
00051 const Object *getObject() const;
00052
00053 void setData(Data);
00054 Data getData() const;
00055
00056 void setValue(const Value &);
00057 const Value& getValue() const;
00058
00059 ~CollItem() {delete data;}
00060
00061 private:
00062 void init(Collection *_coll, Collection::ItemId, int);
00063 Collection *coll;
00064 Collection::ItemId id;
00065 Oid oid;
00066 const Object *o;
00067 Value value;
00068 Data data;
00069 int state;
00070 Bool is_oid, is_object, is_value, is_data;
00071
00072 public:
00073 void setColl(Collection *_coll) {
00074 coll = _coll;
00075 }
00076 };
00077
00078 class CollCache {
00079
00080 public:
00081 CollCache(Collection *, unsigned int magorder, Size,
00082 unsigned int max = 0xffffffff);
00083
00084 Status insert(const Oid&, Collection::ItemId, int);
00085 Status insert(const Object *, Collection::ItemId, int);
00086 Status insert(const Value&, Collection::ItemId, int);
00087 Status insert(Data, Collection::ItemId, int);
00088
00089 Status suppressOid(CollItem *item);
00090 Status suppressObject(CollItem *item);
00091 Status suppressValue(CollItem *item);
00092 Status suppressData(CollItem *item);
00093 Status suppress(CollItem *item);
00094
00095 CollItem *get(Collection::ItemId);
00096 CollItem *get(const Object *);
00097 CollItem *get(const Oid&);
00098 CollItem *get(const Value &);
00099 CollItem *get(Data);
00100
00101 LinkedList *getList();
00102
00103 void empty(Bool = False);
00104
00105 ~CollCache();
00106
00107 private:
00108 Collection *coll;
00109 Collection::ItemId mask;
00110 unsigned int nkeys;
00111 Size item_size;
00112
00113 void remove(LinkedList **);
00114
00115 LinkedList *list;
00116 LinkedList **oid_list;
00117 LinkedList **id_list;
00118 LinkedList **obj_list;
00119 LinkedList **value_list;
00120 LinkedList **data_list;
00121
00122 int nitems;
00123 unsigned int max_items;
00124 CollItem *get_realize(int, LinkedList **);
00125 Status insert_realize(const void *, int, Collection::ItemId, unsigned int, LinkedList **);
00126
00127 inline unsigned int key_id(Collection::ItemId id) { return id & mask; }
00128 inline unsigned int key_oid(const Oid &oid) { return oid.getNX() & mask; }
00129 inline unsigned int key_obj(const Object *o) { return (((long)o)>>2) & mask; }
00130 inline unsigned int key_data(Data data)
00131 {
00132 Data p = data;
00133 unsigned int key = 0;
00134 int r = (item_size < 8 ? item_size : 8);
00135
00136 for (int i = 0; i < r; i++)
00137 key += (int)*p++;
00138
00139 return key & mask;
00140 }
00141
00142 inline int key_value(const Value &value) {
00143 return 0;
00144 }
00145
00146 void init();
00147
00148 public:
00149 void setColl(Collection *);
00150 };
00151 }
00152
00153 #endif