File indexing completed on 2024-04-21 03:44:00
0001 #ifndef _SkipList_H 0002 #define _SkipList_H 0003 0004 /* 0005 SkipList.h 0006 0007 See: Pugh, William, "Skip Lists: A Probabilistic Alternative to Balanced Trees" 0008 0009 */ 0010 #include <limits.h> // INT_MAX 0011 #include <SkipListElement.h> 0012 0013 #define SKIPLIST_NOT_FOUND -1 0014 0015 class SkipListElement; 0016 0017 class LINKAGE SkipList 0018 { 0019 public: 0020 SkipList(float probability = 0.5); 0021 ~SkipList(); 0022 0023 /// insert new element 0024 void insert(const Key searchKey, const Value value); 0025 /// search element with key NGT searchKey 0026 Key findMAX(const Key searchKey) const; 0027 /// search element with key NLT searchKey 0028 Key findMIN(const Key searchKey) const; 0029 /* ITERATOR SUPPRT */ 0030 void reset() { iter = myHeader->getElement(0); } 0031 int step() 0032 { 0033 iter = iter->getElement(0); 0034 return (iter != NIL); 0035 } 0036 0037 Key getkey() 0038 { 0039 if (iter != NIL) 0040 return iter->getKey(); 0041 else 0042 return (Key)-1; 0043 } 0044 0045 Value getvalue() 0046 { 0047 if (iter != NIL) 0048 return iter->getValue(); 0049 else 0050 return (Value)-1; 0051 } 0052 0053 /// free element with key 0054 void free(const Key searchKey); 0055 void freeRange(const Key loKey, const Key hiKey); 0056 0057 /// statistics; 0058 void stat(); 0059 0060 private: 0061 float myProbability; 0062 /// the header (first) list element 0063 SkipListElement *myHeader; 0064 SkipListElement *iter; 0065 long myLength; 0066 }; 0067 0068 #endif // _SkipList_H