![]() |
VR-Link API Documentation for HLA 1516
|
00001 /********************************************************************* 00002 ** Copyright (c) 1997 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: oldHashList.h,v $ $Revision: 1.2 $ $State: Exp $ 00007 *********************************************************************/ 00008 00009 #ifndef oldHashList_H_ 00010 #define oldHashList_H_ 00011 00012 #include "vlList.h" 00013 00014 // This file is no longer part of VR-Link. The header and source are provided 00015 // as an example for customers who require backwards compatability. These 00016 // classes are no longer supported by MAK. Customers may use the classes 00017 // as they wish without obtaining permission from MAK. 00018 00019 // In VR-Link 3.3, we significantly changed the semantics of our DtHashlist 00020 // class. The new version is defined in hashlist.h. The older DtHashlist 00021 // class has been renamed DtOldHashlist, and is still defined here in this 00022 // file for backwards compatibility. While we suggest that you port your 00023 // code to the new DtHashlist, which is cleaner and easier to use, if you 00024 // do not want to make that change, you can just use DtOldHashlist wherever 00025 // you used to use DtHashlist, and the rest of your old code should work. 00026 00027 #ifdef DtUSE_UTILITIES_NAMESPACE 00028 namespace DtUSE_UTILITIES_NAMESPACE 00029 { 00030 #endif 00031 00032 union DT_DLL_VLUTIL DtHashKey 00033 { 00034 DtHashKey(int ii) { i = ii; } 00035 DtHashKey(const void *pp) { p = (void *) pp; } 00036 int i; 00037 void *p; 00038 }; 00039 00040 class DT_DLL_VLUTIL DtHashedItem 00041 { 00042 public: 00043 friend class DtOldHashlist; 00044 00045 DtHashKey key() { return myKey; } 00046 DtListItem *listItem() { return myItem; } 00047 protected: 00048 DtHashedItem(DtHashKey k, DtListItem *item) : myKey(k), myItem(item) {} 00049 DtHashKey myKey; 00050 DtListItem *myItem; 00051 }; 00052 00053 class DT_DLL_VLUTIL DtOldHashlist 00054 { 00055 public: 00056 DtOldHashlist(unsigned numBuckets); 00057 virtual ~DtOldHashlist(); 00058 00059 const DtList *list() const; 00060 virtual unsigned hash(DtHashKey key) const; 00061 virtual int isEqual(DtHashKey key1, DtHashKey key2) const; 00062 00063 // In the event that an Item with key already exists, then add 00064 // will replace the data and move it to the location in list. 00065 // If your data was alloced, do not add unless you know key is 00066 // unique, or a memory leak will result. 00067 00068 DtListItem *add (DtHashKey key, void *data); 00069 DtListItem *addToStart(DtHashKey key, void *data); 00070 DtListItem *addToEnd (DtHashKey key, void *data); 00071 DtListItem *addBefore(DtHashKey key, void *data, 00072 DtListItem *before); 00073 DtListItem *addAfter(DtHashKey key, void *data, 00074 DtListItem *after); 00075 00076 virtual void *remove(DtHashKey key); 00077 virtual void *operator[] (DtHashKey key) const; 00078 virtual void *lookup(DtHashKey key) const; 00079 00080 DtListItem *itemLookup(DtHashKey key) const; 00081 00082 unsigned nBuckets(void) const; 00083 unsigned bucketCount(unsigned index) const; 00084 00085 protected: 00086 DtList *bucket(DtHashKey key) const; 00087 void addToBucket(DtHashKey k, DtListItem *item); 00088 DtListItem *removeFromBucket(DtHashKey key); 00089 DtList *myList; 00090 DtList *buckets; 00091 unsigned nbuck; 00092 }; 00093 00094 inline const DtList *DtOldHashlist::list() const 00095 { 00096 return myList; 00097 } 00098 00099 inline int DtOldHashlist::isEqual(DtHashKey key1, DtHashKey key2) const 00100 { 00101 return key1.i == key2.i; 00102 } 00103 00104 inline unsigned DtOldHashlist::hash(DtHashKey key) const 00105 { 00106 return key.i % nbuck; 00107 } 00108 00109 inline DtList *DtOldHashlist::bucket(DtHashKey key) const 00110 { 00111 return &buckets[hash(key)]; 00112 } 00113 00114 inline void *DtOldHashlist::lookup (DtHashKey key) const 00115 { 00116 DtListItem *item = itemLookup(key); 00117 return (item ? item->data() : NULL); 00118 } 00119 00120 inline void *DtOldHashlist::operator[] (DtHashKey key) const 00121 { 00122 return lookup(key); 00123 } 00124 00125 inline unsigned int DtOldHashlist::nBuckets() const 00126 { 00127 return nbuck; 00128 } 00129 00130 inline unsigned int DtOldHashlist::bucketCount(unsigned index) const 00131 { 00132 return buckets[index].count(); 00133 } 00134 00135 inline DtListItem *DtOldHashlist::add(DtHashKey key, void *data) 00136 { 00137 return addAfter(key, data, list()->last()); 00138 } 00139 00140 inline DtListItem *DtOldHashlist::addToStart(DtHashKey key, void *data) 00141 { 00142 return addAfter(key, data, NULL); 00143 } 00144 00145 inline DtListItem *DtOldHashlist::addToEnd (DtHashKey key, void *data) 00146 { 00147 return addAfter(key, data, list()->last()); 00148 } 00149 00150 inline DtListItem *DtOldHashlist::addBefore(DtHashKey key, void *data, 00151 DtListItem *before) 00152 { 00153 return addAfter(key, data, before ? before->prev() : (DtListItem*)NULL); 00154 } 00155 00156 class DT_DLL_VLUTIL DtOldIntrusiveHashlist : public DtOldHashlist 00157 { 00158 public: 00159 DtOldIntrusiveHashlist(unsigned numBuckets); 00160 }; 00161 00162 #ifdef DtUSE_UTILITIES_NAMESPACE 00163 } // end of namespace DtUSE_UTILITIES_NAMESPACE 00164 #endif 00165 00166 #endif /* _HASHLIST_H_ */