javahash.tpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. template <class ELEMENT>
  14. void JavaHashTableOf<ELEMENT>::onAdd(void * et)
  15. {
  16. if(keep) static_cast<ELEMENT *>(et)->Link();
  17. else static_cast<ELEMENT *>(et)->addObserver(*this);
  18. }
  19. template <class ELEMENT>
  20. void JavaHashTableOf<ELEMENT>::onRemove(void * et)
  21. {
  22. if(keep) static_cast<ELEMENT *>(et)->Release();
  23. else static_cast<ELEMENT *>(et)->removeObserver(*this);
  24. }
  25. template <class ELEMENT>
  26. bool JavaHashTableOf<ELEMENT>::addOwn(ELEMENT & donor)
  27. {
  28. if(this->add(donor))
  29. {
  30. donor.Release();
  31. return true;
  32. }
  33. return false;
  34. }
  35. template <class ELEMENT>
  36. bool JavaHashTableOf<ELEMENT>::replaceOwn(ELEMENT & donor)
  37. {
  38. if(this->replace(donor))
  39. {
  40. donor.Release();
  41. return true;
  42. }
  43. return false;
  44. }
  45. template <class ELEMENT>
  46. ELEMENT * JavaHashTableOf<ELEMENT>::findLink(const ELEMENT & findParam) const
  47. {
  48. ELEMENT * found = SuperHashTableOf<ELEMENT, ELEMENT>::find(&findParam);
  49. if(found) found->Link();
  50. return found;
  51. }
  52. template <class ELEMENT>
  53. bool JavaHashTableOf<ELEMENT>::onNotify(INotification & notify)
  54. {
  55. bool ret = true;
  56. if (notify.getAction() == NotifyOnDispose)
  57. {
  58. ELEMENT * mapping = (ELEMENT *)(notify.querySource());
  59. ret = this->removeExact(mapping);
  60. assertex(ret);
  61. }
  62. return ret;
  63. }
  64. #if defined(IHASH_DEFINED)&&defined(ICOMPARE_DEFINED)
  65. template <class ELEMENT>
  66. ELEMENT *JavaHashTableOf<ELEMENT>::findCompare(ICompare *icmp,void * (ELEMENT::*getPtr)() const,unsigned hash,const void *val) const
  67. {
  68. unsigned v;
  69. #ifdef HASHSIZE_POWER2
  70. v = hash & _SELF::tablemask;
  71. #else
  72. v = hash % _SELF::tablesize;
  73. #endif
  74. unsigned vs = v;
  75. do
  76. {
  77. ELEMENT * et = static_cast<ELEMENT *>(_SELF::table[v]);
  78. if (!et)
  79. break;
  80. if(icmp->docompare(val, (et->*getPtr)()) == 0)
  81. {
  82. _SELF::setCache(v);
  83. return et;
  84. }
  85. v++;
  86. if(v == _SELF::tablesize)
  87. v = 0;
  88. } while (v != vs);
  89. return NULL;
  90. }
  91. #endif