//===========================================================================// // File: hash.hh // // Project: MUNGA Brick: Connection Library // // Contents: // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 12/15/94 ECH Initial coding. // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // PROPRIETARY AND CONFIDENTIAL // //===========================================================================// #if !defined(HASH_HPP) # define HASH_HPP # if !defined(SRTSKT_HPP) # include # endif # if !defined(VCHAIN_HPP) # include # endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hash ~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Hash: public SortedSocket { friend class HashIterator; public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructor, Destructor and Testing //-------------------------------------------------------------------- // Hash( CollectionSize size, Node *node, Logical has_unique_entries ); ~Hash(); Logical TestInstance() const; static Logical TestClass(); static Logical ProfileClass(); protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // void AddImplementation(Plug *plug); void AddValueImplementation( Plug *plug, const void *value ); Plug *FindImplementation(const void *value); // //-------------------------------------------------------------------- // Protected data //-------------------------------------------------------------------- // VChain **hashTable; CollectionSize hashTableSize; private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // virtual VChain* MakeVChain(); virtual IteratorPosition GetHashIndex(const void *value); void BuildHashTable(); }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class HashOf: public Hash { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // HashOf( CollectionSize size, Node *node, Logical has_unique_entries ); ~HashOf(); // //-------------------------------------------------------------------- // Socket methods (see Socket for full listing) //-------------------------------------------------------------------- // void AddValue( T plug, const V &value ) {AddValueImplementation(Cast_Object(Plug*,plug), &value);} T Find(const V &value) {return (T)FindImplementation(&value);} private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // VChain* MakeVChain(); IteratorPosition GetHashIndex(const void *value); }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~ template HashOf::HashOf( CollectionSize size, Node *node, Logical has_unique_entries ): Hash( size, node, has_unique_entries ) { } template HashOf::~HashOf() { } template VChain* HashOf::MakeVChain() { return new VChainOf(GetReleaseNode(), HasUniqueEntries()); } template IteratorPosition HashOf::GetHashIndex(const void *value) { Check_Pointer(value); return (IteratorPosition(*(V*)value) % hashTableSize); // return ((IteratorPosition)*(V*)value % hashTableSize); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~ class HashIterator: public SortedIterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructors, Destructor and testing //-------------------------------------------------------------------- // HashIterator(Hash *hash); ~HashIterator(); Logical TestInstance() const; // //-------------------------------------------------------------------- // Iterator methods (see Iterator for full listing) //-------------------------------------------------------------------- // void First(); void Last(); void Next(); void Previous(); CollectionSize GetSize(); void Remove(); protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // #if 0 void* ReadAndNextImplementation(); void* ReadAndPreviousImplementation(); #endif void* GetCurrentImplementation(); #if 0 void* GetNthImplementation(CollectionSize index); #endif Plug* FindImplementation(const void *value); private: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Private interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // void ReceiveMemo( IteratorMemo memo, void *content ); void DeleteVChainIterator(); void NextVChainIterator(IteratorPosition index); // //-------------------------------------------------------------------- // Private data //-------------------------------------------------------------------- // VChain **hashTable; CollectionSize hashTableSize; IteratorPosition currentPosition; VChainIterator *vchainIterator; }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashIteratorOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class HashIteratorOf: public HashIterator { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Constructors and Destructor //-------------------------------------------------------------------- // HashIteratorOf(HashOf *hash); HashIteratorOf(HashOf &hash); ~HashIteratorOf(); // //-------------------------------------------------------------------- // Iterator methods (see Iterator for full listing) //-------------------------------------------------------------------- // T ReadAndNext() {return (T)ReadAndNextImplementation();} T ReadAndPrevious() {return (T)ReadAndPreviousImplementation();} T GetCurrent() {return (T)GetCurrentImplementation();} T GetNth(CollectionSize index) {return (T)GetNthImplementation(index);} T Find(const V &value) {return (T)FindImplementation(&value);} }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~ HashIteratorOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~ template HashIteratorOf::HashIteratorOf(HashOf *hash): HashIterator(hash) { } template HashIteratorOf::HashIteratorOf(HashOf &hash): HashIterator(&hash) { } template HashIteratorOf::~HashIteratorOf() { } #endif