murmur3.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/intreadwrite.h"
  21. #include "libavutil/mem.h"
  22. #include "libavutil/murmur3.h"
  23. int main(void)
  24. {
  25. int i;
  26. uint8_t hash_result[16] = {0};
  27. struct AVMurMur3 *ctx = av_murmur3_alloc();
  28. #if 1
  29. uint8_t in[256] = {0};
  30. uint8_t *hashes = av_mallocz(256 * 16);
  31. for (i = 0; i < 256; i++)
  32. {
  33. in[i] = i;
  34. av_murmur3_init_seeded(ctx, 256 - i);
  35. // Note: this actually tests hashing 0 bytes
  36. av_murmur3_update(ctx, in, i);
  37. av_murmur3_final(ctx, hashes + 16 * i);
  38. }
  39. av_murmur3_init_seeded(ctx, 0);
  40. av_murmur3_update(ctx, hashes, 256 * 16);
  41. av_murmur3_final(ctx, hash_result);
  42. av_free(hashes);
  43. av_freep(&ctx);
  44. printf("result: 0x%"PRIx64" 0x%"PRIx64"\n", AV_RL64(hash_result), AV_RL64(hash_result + 8));
  45. // official reference value is 32 bit
  46. return AV_RL32(hash_result) != 0x6384ba69;
  47. #else
  48. uint8_t *in = av_mallocz(512*1024);
  49. av_murmur3_init(ctx);
  50. for (i = 0; i < 40*1024; i++)
  51. av_murmur3_update(ctx, in, 512*1024);
  52. av_murmur3_final(ctx, hash_result);
  53. av_free(in);
  54. return hash_result[0];
  55. #endif
  56. }