HashTable.C 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: HashTable.C /main/1 1996/07/29 16:52:50 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifndef HashTable_DEF_INCLUDED
  27. #define HashTable_DEF_INCLUDED 1
  28. #ifdef SP_NAMESPACE
  29. namespace SP_NAMESPACE {
  30. #endif
  31. template<class K, class V>
  32. void HashTable<K,V>::insert(const K &key, const V &value, Boolean replace)
  33. {
  34. HashTableItem<K, V> *newItem = new HashTableItem<K, V>(key, value);
  35. HashTableItem<K, V> *tem = (HashTableItem<K, V> *)table_.insert(newItem);
  36. if (tem) {
  37. delete newItem;
  38. if (replace) {
  39. tem->key = key;
  40. tem->value = value;
  41. }
  42. }
  43. }
  44. template<class K, class V>
  45. HashTableItem<K,V>::HashTableItem(const K &k, const V &v)
  46. : HashTableItemBase<K>(k), value(v)
  47. {
  48. }
  49. template<class K, class V>
  50. HashTableItemBase<K> *HashTableItem<K,V>::copy() const
  51. {
  52. return new HashTableItem<K, V>(*this);
  53. }
  54. #ifdef SP_NAMESPACE
  55. }
  56. #endif
  57. #endif /* not HashTable_DEF_INCLUDED */