home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / CLASSINC.ZIP / HASHTBL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.2 KB  |  134 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  HASHTBL.H                                                             */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1992                            */
  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. #pragma option -Vo-
  38. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  39. #pragma option -po-
  40. #endif
  41.  
  42. _CLASSDEF(ContainerIterator)
  43. _CLASSDEF(HashTable)
  44. _CLASSDEF(HashTableIterator)
  45.  
  46. class _CLASSTYPE HashTable : public Collection
  47. {
  48.  
  49. public:
  50.  
  51.     friend class HashTableIterator;
  52.  
  53.     HashTable( sizeType = DEFAULT_HASH_TABLE_SIZE );
  54.     virtual ~HashTable() { flush(); }
  55.  
  56.     virtual void add( Object _FAR & );
  57.     virtual void detach( Object _FAR &, DeleteType = NoDelete );
  58.     virtual void flush( DeleteType = DefDelete );
  59.  
  60.     virtual int isEmpty() const
  61.         {
  62.         return itemsInContainer == 0;
  63.         }
  64.  
  65.     virtual countType getItemsInContainer() const
  66.         {
  67.         return itemsInContainer;
  68.         }
  69.  
  70.     virtual Object _FAR & findMember( Object _FAR & ) const;
  71.  
  72.     virtual ContainerIterator& initIterator() const;
  73.  
  74.     virtual classType isA() const
  75.         {
  76.         return hashTableClass;
  77.         }
  78.  
  79.     virtual char _FAR *nameOf() const
  80.         {
  81.         return "HashTable";
  82.         }
  83.  
  84. private:
  85.  
  86.     hashValueType getHashValue( Object _FAR & ) const;
  87.     sizeType size;
  88.     BI_IVectorImp<Object> table;
  89.  
  90.     unsigned itemsInContainer;
  91.  
  92.     DeleteType delItem( DeleteType dt )
  93.         {
  94.         return delObj(dt) ? Delete : NoDelete;
  95.         }
  96.  
  97. };
  98.  
  99. inline sizeType HashTable::getHashValue( Object _FAR & ofObject ) const
  100. {
  101.     return ofObject.hashValue() % size;
  102. }
  103.  
  104. class _CLASSTYPE HashTableIterator : public ContainerIterator
  105. {
  106.  
  107. public:
  108.  
  109.     HashTableIterator( const HashTable _FAR & );
  110.     ~HashTableIterator();
  111.  
  112.     virtual operator int();
  113.     virtual Object _FAR & current();
  114.     virtual Object _FAR & operator ++ ( int );
  115.     virtual Object _FAR & operator ++ ();
  116.     virtual void restart();
  117.  
  118. private:
  119.  
  120.     BI_IVectorIteratorImp<Object> _FAR *arrayIterator;
  121.     ContainerIterator _FAR *listIterator;
  122.     const HashTable _FAR & beingIterated;
  123.  
  124.     void scan();
  125. };
  126.  
  127. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  128. #pragma option -po.
  129. #endif
  130. #pragma option -Vo.
  131.  
  132. #endif  // __HASHTBL_H
  133.  
  134.