summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1993-12-22 12:25:31 +0000
committerchatty1993-12-22 12:25:31 +0000
commitfa5d3f424a09155e714394eb9b501c81373e0973 (patch)
treea1f9dc5810ed4a8078a2592bdfc4ee109b3164f1
parent5bbc69b1ccaf26b1f4670668bc11aba86e92139d (diff)
downloadivy-league-fa5d3f424a09155e714394eb9b501c81373e0973.zip
ivy-league-fa5d3f424a09155e714394eb9b501c81373e0973.tar.gz
ivy-league-fa5d3f424a09155e714394eb9b501c81373e0973.tar.bz2
ivy-league-fa5d3f424a09155e714394eb9b501c81373e0973.tar.xz
serious reorganization
-rw-r--r--utils/IdTable.h90
1 files changed, 54 insertions, 36 deletions
diff --git a/utils/IdTable.h b/utils/IdTable.h
index 0b64219..ad95411 100644
--- a/utils/IdTable.h
+++ b/utils/IdTable.h
@@ -3,7 +3,7 @@
*
* by Stephane Chatty
*
- * Copyright 1990, 1991, 1992
+ * Copyright 1990, 1991, 1992, 1993
* Laboratoire de Recherche en Informatique (LRI)
* Centre d'Etudes de la Navigation Aerienne (CENA)
*
@@ -19,61 +19,79 @@
#include "word.h"
#include "bool.h"
-/*
- * TID_MASK = 2^TID_SHIFT = max table size
- * TID_MASK = TID_SHIFT bits set to 1.
- */
-#define TID_MAX (2 << 16)
-#define TID_SHIFT 16
-#define TID_MASK 0xffff
-
-struct CcuIdCell {
- sword chk; // the check number
- sword typ; // for the appli, for free list when not allocated
- const void* obj; // the object
-};
+typedef void CcuIdItem;
+typedef lword CcuID;
+typedef sword CcuIdType;
+typedef sword CcuIdIndex;
class CcuIdTable {
friend class CcuIdIter;
+friend class CcuIdCell;
protected:
- CcuIdCell* entries; // the table itself
- CcuIdCell* last; // its end
- sword free; // index of first free entry
- sword last_free; // index of end of free list
- sword num_free; // number of free entries
+ CcuIdCell* Entries; // the table itself
+ CcuIdCell* LastCell; // its end
+ CcuIdIndex FirstFree; // index of first free entry
+ CcuIdIndex LastFree; // index of end of free list
+ short NumFree; // number of free Entries
bool Grow (int);
public:
- CcuIdTable (int = 4); // initial size should be power of 2 *** 4 for testing
+ CcuIdTable (int); // initial size should be power of 2
- lword Store (const void*, sword = 0);
- bool Remove (lword);
- const void* Get (lword, sword* = 0);
- void Change (lword, const void*, sword = 0);
+ CcuID Store (CcuIdItem*, CcuIdType = 0);
+ CcuIdItem* Get (CcuID, CcuIdType* = 0);
+ CcuIdItem* Remove (CcuID, bool* = 0, CcuIdType* = 0);
+ void Change (CcuID, CcuIdItem*, CcuIdType = 0);
};
class CcuIdIter {
+public:
+ enum iditer_status { Normal, StartOfTable, EndOfTable };
+
protected:
- CcuIdTable* idt;
- CcuIdCell* entries;
- CcuIdCell* cur;
+ const CcuIdTable* TheTable;
+ iditer_status StatusFlag;
+ CcuIdCell* Entries;
+ CcuIdCell* CurCell;
- void Step ();
-
public:
- CcuIdIter (CcuIdTable& t) { idt = &t; cur = entries = t.entries; Step (); }
+inline CcuIdIter (const CcuIdTable& t) : TheTable (&t), StatusFlag (StartOfTable) { CurCell = Entries = t.Entries; }
+inline void Reset () { CurCell = Entries = TheTable->Entries; StatusFlag = StartOfTable; }
+inline CcuIdIter& operator = (const CcuIdTable& t) { TheTable = &t; StatusFlag = StartOfTable; CurCell = Entries = t.Entries; return *this; }
+inline CcuIdIter& operator = (const CcuIdIter& it) { TheTable = it.TheTable; StatusFlag = it.StatusFlag; CurCell = it.CurCell; Entries = it.Entries; return *this; }
+
+ CcuIdIter& operator ++ ();
+ CcuIdItem* Current () const;
+inline CcuIdItem* operator * () const { return Current (); }
+inline operator int () const { return StatusFlag == Normal; }
+ CcuIdType CurType () const;
+ CcuID CurId () const;
- const void* operator () () { Step (); return cur ? cur->obj : 0; }
- const void* operator ++ () { Step (); return cur ? cur++->obj : 0; }
- const void* Current () { return cur ? cur->obj : 0; }
- sword CurType () { return cur ? cur->typ : 0; }
- lword CurId () { return cur ? (cur -> chk << TID_SHIFT) | (cur - entries) : 0; }
+};
+template <class ITEM> class CcuIdTableOf : public CcuIdTable {
+public:
+inline CcuIdTableOf (int sz) : CcuIdTable (sz) {}
- void Reset () { cur = entries = idt->entries; }
+inline CcuID Store (ITEM* it, CcuIdType typ = 0) { return CcuIdTable::Store (it, typ); }
+inline ITEM* Get (CcuID id, CcuIdType* typ = 0) { return (ITEM*) CcuIdTable::Get (id, typ); }
+inline ITEM* Remove (CcuID id, bool* f = 0, CcuIdType* t = 0) { return (ITEM*) CcuIdTable::Remove (id, f, t); }
+inline void Change (CcuID id, ITEM* i, CcuIdType t = 0) { CcuIdTable::Change (id, i, t); }
};
+template <class ITEM> class CcuIdIterOf : public CcuIdIter {
+public:
+inline CcuIdIterOf (CcuIdTableOf <ITEM> & t) : CcuIdIter (t) { }
+inline CcuIdIterOf& operator = (const CcuIdTableOf <ITEM>& t) { return (CcuIdIterOf&) CcuIdIter::operator = (t); }
+inline CcuIdIterOf& operator = (const CcuIdIterOf& li) { return (CcuIdIterOf&) CcuIdIter::operator = (li); }
+inline CcuIdIterOf& operator ++ () { return (CcuIdIterOf&) CcuIdIter::operator ++ (); }
+inline ITEM* Current () const { return (ITEM*) CcuIdIter::Current (); }
+inline ITEM* operator * () const { return Current (); }
+};
+
+
+
#endif /* IdTable_H_ */