33 #ifndef H_COEDEUTIL_DICTIONARY_INCLUDED
34 #define H_COEDEUTIL_DICTIONARY_INCLUDED
70 void Remove(
const LookupID &);
75 bool Query(
const LookupID &);
85 std::vector<T>
List();
91 std::stack<size_t> deadList;
92 std::vector<T> entryList;
93 std::vector<bool> entryValid;
109 bool operator==(
const LookupID & c)
const;
110 bool operator!=(
const LookupID & c)
const;
112 friend bool operator<(
const LookupID & l,
const LookupID & r) {
113 if (l.TableID == r.TableID) {
114 return l.lookupID < r.lookupID;
127 LookupID(
size_t TableID_,
size_t id_) :
142 class LookupLibrary {
147 friend class LookupID;
150 static void AssertOpen();
153 static bool IsTableAlias(uint64_t a, uint64_t b);
156 static uint64_t AcquireTableID(
void *);
159 static void * CurrentTableID(uint64_t);
162 static void RemoveTable(
void *);
167 static uint64_t MapTableData(uint64_t TableID, uint64_t dataSlot);
170 static void UnmapTableData(uint64_t TableID, uint64_t lookupID);
173 static bool IsDataMapped(uint64_t TableID, uint64_t lookupID);
176 static uint64_t GetDataSlot(uint64_t TableID, uint64_t lookupID);
186 LookupLibrary::AssertOpen();
187 thisID = LookupLibrary::AcquireTableID(
this);
192 LookupLibrary::RemoveTable(
this);
198 if (!deadList.empty()) {
199 size_t id = deadList.top();
200 entryList[id] = item;
201 entryValid[id] =
true;
203 return LookupID(thisID, LookupLibrary::MapTableData(thisID,
id));
205 entryList.push_back(item);
206 entryValid.push_back(
true);
207 LookupID out(thisID, LookupLibrary::MapTableData(thisID, entryList.size() - 1));
216 if (!
id.Valid())
return;
219 uint64_t vectorSlot = LookupLibrary::GetDataSlot(
id.TableID,
id.lookupID);
220 entryValid[vectorSlot] =
false;
221 deadList.push(vectorSlot);
222 LookupLibrary::UnmapTableData(
id.TableID,
id.lookupID);
228 if (!
id.Valid())
return false;
230 return LookupLibrary::IsTableAlias(
id.TableID, thisID);
239 return entryList[LookupLibrary::GetDataSlot(thisID,
id.lookupID)];
247 for(
size_t i = 0; i < entryList.size(); ++i) {
249 out.push_back(entryList[i]);
T & Find(LookupID)
Finds an entry based on the ID.
Definition: Table.h:234
LookupID Insert(T)
Adds an entry to the lookup table. A lookupID is returned.
Definition: Table.h:196
void Remove(const LookupID &)
Dissasociates an ID from an entry.
Definition: Table.h:215
std::vector< T > List()
Returns a std::vector holding each member added.
Definition: Table.h:245
An associative container that issues each member an ID guaranteed to be unique for the duration of th...
Definition: Table.h:58
bool Query(const LookupID &)
Returns whehter or not the ID is owned by this table.
Definition: Table.h:227