Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1997.
  5. //
  6. // File: tstrhash.hxx
  7. //
  8. // Contents: CHashtable, a really simple hash table
  9. //
  10. // History: 2-Sep-97 dlee Created
  11. //
  12. //----------------------------------------------------------------------------
  13. //+---------------------------------------------------------------------------
  14. //
  15. // Class: CHashtable
  16. //
  17. // Purpose: Simple hash table, doesn't own the entries, not updatable
  18. //
  19. // History: 2-Sep-97 dlee Created
  20. //
  21. //----------------------------------------------------------------------------
  22. template<class T> class CHashtable
  23. {
  24. public:
  25. CHashtable( ULONG size = 71 ) : _aHead( size )
  26. {
  27. RtlZeroMemory( _aHead.GetPointer(), size * sizeof( T * ) );
  28. }
  29. T * Lookup( WCHAR const * pwc )
  30. {
  31. ULONG x = ( T::Hash( pwc ) % _aHead.Count() );
  32. T * p = _aHead[ x ];
  33. while ( 0 != p )
  34. {
  35. if ( 0 == p->Compare( pwc ) )
  36. return p;
  37. p = p->Next();
  38. }
  39. return 0;
  40. }
  41. void Add( T * p )
  42. {
  43. ULONG x = ( p->Hash() % _aHead.Count() );
  44. p->Next() = _aHead[ x ];
  45. _aHead[ x ] = p;
  46. }
  47. private:
  48. XArray<T *> _aHead;
  49. };