test.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2015 Kazuho Oku
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to
  6. * deal in the Software without restriction, including without limitation the
  7. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. * sell copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. * IN THE SOFTWARE.
  21. */
  22. #include <inttypes.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "golombset.h"
  26. int main(int argc, char **argv)
  27. {
  28. uint64_t keys[] = {151, 192, 208, 269, 461, 512, 526, 591, 662, 806, 831, 866, 890,
  29. 997, 1005, 1017, 1134, 1207, 1231, 1327, 1378, 1393, 1418, 1525, 1627, 1630};
  30. const size_t num_keys = sizeof(keys) / sizeof(keys[0]);
  31. unsigned char buf[1024];
  32. size_t bufsize = sizeof(buf);
  33. if (golombset_encode(6, keys, num_keys, buf, &bufsize) != 0) {
  34. fprintf(stderr, "golombset_encode failed\n");
  35. return 111;
  36. }
  37. printf("encoded %zu entries into %zu bytes\n", num_keys, bufsize);
  38. uint64_t decoded_keys[num_keys];
  39. size_t num_decoded_keys = num_keys;
  40. if (golombset_decode(6, buf, bufsize, decoded_keys, &num_decoded_keys) != 0) {
  41. fprintf(stderr, "golombset_decode failed\n");
  42. return 111;
  43. }
  44. if (num_decoded_keys != num_keys) {
  45. fprintf(stderr, "unexpected number of outputs\n");
  46. return 111;
  47. }
  48. if (memcmp(keys, decoded_keys, sizeof(keys[0]) * num_keys) != 0) {
  49. fprintf(stderr, "output mismatch\n");
  50. return 111;
  51. }
  52. return 0;
  53. }