// file: $isip/class/dstr/HashKey/HashKey.h // version: $Id: HashKey.h 9030 2003-02-18 15:22:39Z alphonso $ // // make sure definitions are only made once // #ifndef ISIP_HASH_KEY #define ISIP_HASH_KEY // isip include files // #ifndef ISIP_STRING #include #endif // HashKey: a generic class the allows the user to use any TObject as // the key of the HashTable, i.e., the TObject pointer is hashed // template class HashKey { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 42100; static const int32 ERR_NOTDEF = 42101; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // define the array of hash keys // TObject* obj1_d; TObject* obj2_d; // define the number of pointers // int32 length_d; // debugging parameters and static memory manager // static Integral::DEBUG debug_level_d; static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // static methods: // diagnose method is inherited from the Wrapper class // static const String& name(); // setDebug method in inherited from the Wrapper class // // debug method in inherited from the Wrapper class // // method: destructor // ~HashKey() { clear(); } // method: default constructor // HashKey() { obj1_d = (TObject*)NULL; obj2_d = (TObject*)NULL; length_d = 0; } // method: copy constructor // HashKey(const HashKey& arg) { assign(arg); } // method: assign // bool8 assign(const HashKey& arg) { length_d = arg.length_d; obj1_d = arg.obj1_d; obj2_d = arg.obj2_d; return true; } // method: operator= // HashKey& operator=(const HashKey& arg) { assign(arg); return *this; } // method: eq // bool8 eq(const HashKey& arg) const { if ((obj1_d == arg.obj1_d) && (obj2_d == arg.obj2_d)) { return true; } return false; } // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // method: clear // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE) { length_d = 0; obj1_d = (TObject*)NULL; obj2_d = (TObject*)NULL; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // extensions to required methods // //--------------------------------------------------------------------------- // method: assign // bool8 assign(TObject* obj) { if (obj == (TObject*)NULL) { return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } clear(); length_d = 1; obj1_d = obj; return true; } // method: assign // bool8 assign(TObject* obj1, TObject* obj2) { if ((obj1 == (TObject*)NULL) || (obj2 == (TObject*)NULL)) { return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } clear(); length_d = 2; obj1_d = obj1; obj2_d = obj2; return true; } // method: hash // int32 hash(int32 capacity) const { int32 index;//* uint64* vals; switch (length_d) { case 1: vals = new uint64[1]; vals[0] = (uint64)obj1_d; index = Integral::hash(vals, length_d, capacity); delete [] vals; break; case 2: vals = new uint64[2]; vals[0] = (uint64)obj1_d; vals[1] = (uint64)obj2_d; index = Integral::hash(vals, length_d, capacity); delete [] vals; break; default: return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } return index; } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: }; //----------------------------------------------------------------------------- // // we define non-integral constants at the end of class definition for // templates (for non-templates these are defined in the default constructor) // //----------------------------------------------------------------------------- // constants: required constants such as the class name // template const String HashKey::CLASS_NAME(L"HashKey"); // constants: required constants for i/o methods // template const String HashKey::DEF_PARAM(L"item"); // static instantiations: debug level and memory manager // template Integral::DEBUG HashKey::debug_level_d = Integral::NONE; template MemoryManager HashKey::mgr_d(sizeof(HashKey), CLASS_NAME); // below are all the methods for the Node template class // //----------------------------------------------------------------------------- // // required static methods // //----------------------------------------------------------------------------- // method: name // // arguments: none // // return: a static String& containing the class name // // this method returns the class name // template const String& HashKey::name() { // create the static name string for this class and return it // static String cname(CLASS_NAME); cname.clear(); cname.concat(CLASS_NAME); // return the name // return cname; } // end of include file // #endif