bin.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // Bin.h
  20. //
  21. #ifndef __BIN_H
  22. #define __BIN_H
  23. #include "list.h"
  24. #include "OLEString.h"
  25. class BinItem: public ListNode
  26. {
  27. int hash;
  28. OLECHAR *text1;
  29. int text1size;
  30. OLECHAR *text2;
  31. int text2size;
  32. public:
  33. BinItem ( void *data, int hash, OLECHAR *text1, OLECHAR *text2 );
  34. int Same ( int chash, OLECHAR *ctext1, int size1, OLECHAR *ctext2, int size2 );
  35. };
  36. class Bin
  37. {
  38. List *bucket;
  39. int num_buckets;
  40. BinItem *sh_item;
  41. int sh_size1,sh_size2;
  42. int sh_hash;
  43. OLECHAR *sh_text1, *sh_text2;
  44. int calc_hash ( OLECHAR *text );
  45. public:
  46. Bin ( int size = 256 );
  47. ~Bin ();
  48. void Clear ( void );
  49. void* Get ( OLECHAR *text1, OLECHAR *text2 = NULL );
  50. void* GetNext ( void );
  51. void Add ( void *item, OLECHAR *text1, OLECHAR *text2 = NULL );
  52. BinItem* GetBinItem ( OLECHAR *text1, OLECHAR *text2 = NULL );
  53. BinItem* GetBinItem ( void *item );
  54. BinItem* GetNextBinItem ( void );
  55. void Remove ( void *item );
  56. void Remove ( OLECHAR *text1, OLECHAR *text2 = NULL );
  57. void Remove ( BinItem *item );
  58. };
  59. class BinIDItem: public ListNode
  60. {
  61. int id;
  62. public:
  63. BinIDItem ( void *data, int id );
  64. int Same ( int id );
  65. };
  66. class BinID
  67. {
  68. List *bucket;
  69. int num_buckets;
  70. public:
  71. BinID ( int size = 256 );
  72. ~BinID ();
  73. void Clear ( void );
  74. void* Get ( int id );
  75. void Add ( void *item, int id );
  76. BinIDItem* GetBinIDItem ( int id );
  77. BinIDItem* GetBinIDItem ( void *item );
  78. void Remove ( void *item );
  79. void Remove ( int id );
  80. void Remove ( BinIDItem *item );
  81. };
  82. #endif // __BIN_H