da_hashkit.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * twemproxy - A fast and lightweight proxy for memcached protocol.
  3. * Copyright (C) 2011 Twitter, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef _DA_HASHKIT_H_
  18. #define _DA_HASHKIT_H_
  19. #include <stdint.h>
  20. #include <../da_server.h>
  21. #include "../da_log.h"
  22. #define HASH_CODEC(ACTION) \
  23. ACTION( HASH_ONE_AT_A_TIME, one_at_a_time ) \
  24. ACTION( HASH_MD5, md5 ) \
  25. ACTION( HASH_CRC16, crc16 ) \
  26. ACTION( HASH_CRC32, crc32 ) \
  27. ACTION( HASH_CRC32A, crc32a ) \
  28. ACTION( HASH_FNV1_64, fnv1_64 ) \
  29. ACTION( HASH_FNV1A_64, fnv1a_64 ) \
  30. ACTION( HASH_FNV1_32, fnv1_32 ) \
  31. ACTION( HASH_FNV1A_32, fnv1a_32 ) \
  32. ACTION( HASH_HSIEH, hsieh ) \
  33. ACTION( HASH_MURMUR, murmur ) \
  34. ACTION( HASH_JENKINS, jenkins ) \
  35. ACTION( HASH_CHASH, chash ) \
  36. #define DEFINE_ACTION(_hash, _name) _hash,
  37. typedef enum hash_type {
  38. HASH_CODEC( DEFINE_ACTION )
  39. HASH_SENTINEL
  40. } hash_type_t;
  41. #undef DEFINE_ACTION
  42. uint32_t hash_one_at_a_time(const char *key, size_t key_length);
  43. void md5_signature(const unsigned char *key, unsigned int length, unsigned char *result);
  44. uint32_t hash_md5(const char *key, size_t key_length);
  45. uint32_t hash_crc16(const char *key, size_t key_length);
  46. uint32_t hash_crc32(const char *key, size_t key_length);
  47. uint32_t hash_crc32a(const char *key, size_t key_length);
  48. uint32_t hash_fnv1_64(const char *key, size_t key_length);
  49. uint32_t hash_fnv1a_64(const char *key, size_t key_length);
  50. uint32_t hash_fnv1_32(const char *key, size_t key_length);
  51. uint32_t hash_fnv1a_32(const char *key, size_t key_length);
  52. uint32_t hash_hsieh(const char *key, size_t key_length);
  53. uint32_t hash_jenkins(const char *key, size_t length);
  54. uint32_t hash_murmur(const char *key, size_t length);
  55. uint32_t hash_chash(const char *k, size_t length);
  56. int ketama_update(struct server_pool *pool);
  57. uint32_t ketama_dispatch(struct continuum *continuum, uint32_t ncontinuum, uint32_t hash);
  58. #endif