hbfastmap.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @file hbfastmap.h
  3. *
  4. * $LicenseInfo:firstyear=2020&license=viewergpl$
  5. *
  6. * Copyright (c) 2020, Henri Beauchamp.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_HBFASTMAP_H
  32. #define LL_HBFASTMAP_H
  33. // safe_hmap, fast_hmap and flat_hmap are the macros to use (for example, in
  34. // place of boost::unordered_map or boost::container::flat_map) for unordered
  35. // or flat maps you wish to (potentially) speed up.
  36. // safe_hmap is guaranteed not to invalidate all the map iterators on erase()
  37. // of one of its elements and to preserve pointers to keys and values: this is
  38. // the closest thing to boost::unordered_map for phmap's implementation.
  39. // fast_hmap is guaranteed not to invalidate all the map iterators on erase()
  40. // of one of its elements and to preserve pointers to values (but not to keys).
  41. // The hmap_erase #define is provided for a minor optimization with phmap
  42. // containers, which may call a special _erase() method, that does not return
  43. // an iterator (unlike erase()) and is therefore slightly faster. It is only
  44. // valid when passed an iterator (const or not).
  45. #if LL_NO_PHMAP
  46. # include "boost/unordered_map.hpp"
  47. # include "boost/container/flat_map.hpp"
  48. # define safe_hmap boost::unordered_map
  49. # define fast_hmap boost::unordered_map
  50. # define flat_hmap boost::container::flat_map
  51. # define hmap_erase(it) erase(it)
  52. #else
  53. # include "parallel_hashmap/phmap.h"
  54. # define safe_hmap phmap::node_hash_map
  55. # define fast_hmap phmap::flat_hash_map
  56. # define flat_hmap phmap::flat_hash_map
  57. # define hmap_erase(it) _erase(it)
  58. #endif
  59. #endif // LL_HBFASTMAP_H