home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSINC.ZIP / HASHTBL.H < prev    next >
C/C++ Source or Header  |  1992-02-18  |  3KB  |  124 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  HASHTBL.H                                                             */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __HASHTBL_H )
  11. #define __HASHTBL_H
  12.  
  13. #if !defined( __RESOURCE_H )
  14. #include <Resource.h>
  15. #endif  // __RESOURCE_H
  16.  
  17. #if !defined( __CLSTYPES_H )
  18. #include <ClsTypes.h>
  19. #endif  // __CLSTYPES_H
  20.  
  21. #if !defined( __CLSDEFS_H )
  22. #include <ClsDefs.h>
  23. #endif  // __CLSDEFS_H
  24.  
  25. #if !defined( __COLLECT_H )
  26. #include <Collect.h>
  27. #endif  // __COLLECT_H
  28.  
  29. #if !defined( __LIST_H )
  30. #include <List.h>
  31. #endif  // __LIST_H
  32.  
  33. #if !defined( __VECTIMP_H )
  34. #include <VectImp.h>
  35. #endif  // __VECTIMP_H
  36.  
  37. _CLASSDEF(ContainerIterator)
  38. _CLASSDEF(HashTable)
  39. _CLASSDEF(HashTableIterator)
  40.  
  41. class _CLASSTYPE HashTable : public Collection
  42. {
  43.  
  44. public:
  45.  
  46.     friend class HashTableIterator;
  47.  
  48.     HashTable( sizeType = DEFAULT_HASH_TABLE_SIZE );
  49.     virtual ~HashTable() { flush(); }
  50.  
  51.     virtual void add( Object _FAR & );
  52.     virtual void detach( Object _FAR &, DeleteType = NoDelete );
  53.     virtual void flush( DeleteType = DefDelete );
  54.  
  55.     virtual int isEmpty() const
  56.         {
  57.         return itemsInContainer == 0;
  58.         }
  59.  
  60.     virtual countType getItemsInContainer() const
  61.         {
  62.         return itemsInContainer;
  63.         }
  64.  
  65.     virtual Object _FAR & findMember( Object _FAR & ) const;
  66.  
  67.     virtual ContainerIterator& initIterator() const;
  68.  
  69.     virtual classType isA() const
  70.         {
  71.         return hashTableClass;
  72.         }
  73.  
  74.     virtual char _FAR *nameOf() const
  75.         {
  76.         return "HashTable";
  77.         }
  78.  
  79. private:
  80.  
  81.     hashValueType getHashValue( Object _FAR & ) const;
  82.     sizeType size;
  83.     BI_IVectorImp<Object> table;
  84.  
  85.     unsigned itemsInContainer;
  86.  
  87.     DeleteType delItem( DeleteType dt )
  88.         {
  89.         return delObj(dt) ? Delete : NoDelete;
  90.         }
  91.  
  92. };
  93.  
  94. inline sizeType HashTable::getHashValue( Object _FAR & ofObject ) const
  95. {
  96.     return ofObject.hashValue() % size;
  97. }
  98.  
  99. class _CLASSTYPE HashTableIterator : public ContainerIterator
  100. {
  101.  
  102. public:
  103.  
  104.     HashTableIterator( const HashTable _FAR & );
  105.     ~HashTableIterator();
  106.  
  107.     virtual operator int();
  108.     virtual Object _FAR & current();
  109.     virtual Object _FAR & operator ++ ( int );
  110.     virtual Object _FAR & operator ++ ();
  111.     virtual void restart();
  112.  
  113. private:
  114.  
  115.     BI_IVectorIteratorImp<Object> _FAR *arrayIterator;
  116.     ContainerIterator _FAR *listIterator;
  117.     const HashTable _FAR & beingIterated;
  118.  
  119.     void scan();
  120. };
  121.  
  122. #endif  // __HASHTBL_H
  123.  
  124.