t_hash_int.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  3. //
  4. // By downloading, copying, installing or using the software you agree to this license.
  5. // If you do not agree to this license, do not download, install,
  6. // copy or use the software.
  7. //
  8. //
  9. // License Agreement
  10. // For Open Source Computer Vision Library
  11. //
  12. // Copyright (C) 2014, OpenCV Foundation, all rights reserved.
  13. // Third party copyrights are property of their respective owners.
  14. //
  15. // Redistribution and use in source and binary forms, with or without modification,
  16. // are permitted provided that the following conditions are met:
  17. //
  18. // * Redistribution's of source code must retain the above copyright notice,
  19. // this list of conditions and the following disclaimer.
  20. //
  21. // * Redistribution's in binary form must reproduce the above copyright notice,
  22. // this list of conditions and the following disclaimer in the documentation
  23. // and/or other materials provided with the distribution.
  24. //
  25. // * The name of the copyright holders may not be used to endorse or promote products
  26. // derived from this software without specific prior written permission.
  27. //
  28. // This software is provided by the copyright holders and contributors "as is" and
  29. // any express or implied warranties, including, but not limited to, the implied
  30. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  31. // In no event shall the Intel Corporation or contributors be liable for any direct,
  32. // indirect, incidental, special, exemplary, or consequential damages
  33. // (including, but not limited to, procurement of substitute goods or services;
  34. // loss of use, data, or profits; or business interruption) however caused
  35. // and on any theory of liability, whether in contract, strict liability,
  36. // or tort (including negligence or otherwise) arising in any way out of
  37. // the use of this software, even if advised of the possibility of such damage.
  38. //
  39. /** @file
  40. @author Tolga Birdal <tbirdal AT gmail.com>
  41. */
  42. #ifndef __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__
  43. #define __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. namespace cv
  47. {
  48. namespace ppf_match_3d
  49. {
  50. //! @addtogroup surface_matching
  51. //! @{
  52. typedef unsigned int KeyType;
  53. typedef struct hashnode_i
  54. {
  55. KeyType key;
  56. void *data;
  57. struct hashnode_i *next;
  58. } hashnode_i ;
  59. typedef struct HSHTBL_i
  60. {
  61. size_t size;
  62. struct hashnode_i **nodes;
  63. size_t (*hashfunc)(unsigned int);
  64. } hashtable_int;
  65. /** @brief Round up to the next highest power of 2
  66. from http://www-graphics.stanford.edu/~seander/bithacks.html
  67. */
  68. inline static unsigned int next_power_of_two(unsigned int value)
  69. {
  70. --value;
  71. value |= value >> 1;
  72. value |= value >> 2;
  73. value |= value >> 4;
  74. value |= value >> 8;
  75. value |= value >> 16;
  76. ++value;
  77. return value;
  78. }
  79. hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int));
  80. void hashtableDestroy(hashtable_int *hashtbl);
  81. int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data);
  82. int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data);
  83. int hashtableRemove(hashtable_int *hashtbl, KeyType key);
  84. void *hashtableGet(hashtable_int *hashtbl, KeyType key);
  85. hashnode_i* hashtableGetBucketHashed(hashtable_int *hashtbl, KeyType key);
  86. int hashtableResize(hashtable_int *hashtbl, size_t size);
  87. hashtable_int *hashtable_int_clone(hashtable_int *hashtbl);
  88. hashtable_int *hashtableRead(FILE* f);
  89. int hashtableWrite(const hashtable_int * hashtbl, const size_t dataSize, FILE* f);
  90. void hashtablePrint(hashtable_int *hashtbl);
  91. //! @}
  92. } // namespace ppf_match_3d
  93. } // namespace cv
  94. #endif