extzstd 0.0.3.CONCEPT → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/LICENSE +6 -6
  4. data/README.md +26 -45
  5. data/contrib/zstd/CHANGELOG +555 -0
  6. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  7. data/contrib/zstd/CONTRIBUTING.md +392 -0
  8. data/contrib/zstd/COPYING +339 -0
  9. data/contrib/zstd/LICENSE +13 -9
  10. data/contrib/zstd/Makefile +414 -0
  11. data/contrib/zstd/README.md +170 -45
  12. data/contrib/zstd/TESTING.md +44 -0
  13. data/contrib/zstd/appveyor.yml +289 -0
  14. data/contrib/zstd/lib/BUCK +234 -0
  15. data/contrib/zstd/lib/Makefile +354 -0
  16. data/contrib/zstd/lib/README.md +179 -0
  17. data/contrib/zstd/{common → lib/common}/bitstream.h +170 -130
  18. data/contrib/zstd/lib/common/compiler.h +175 -0
  19. data/contrib/zstd/lib/common/cpu.h +215 -0
  20. data/contrib/zstd/lib/common/debug.c +24 -0
  21. data/contrib/zstd/lib/common/debug.h +114 -0
  22. data/contrib/zstd/{common → lib/common}/entropy_common.c +79 -94
  23. data/contrib/zstd/lib/common/error_private.c +55 -0
  24. data/contrib/zstd/lib/common/error_private.h +80 -0
  25. data/contrib/zstd/{common → lib/common}/fse.h +153 -93
  26. data/contrib/zstd/{common → lib/common}/fse_decompress.c +37 -82
  27. data/contrib/zstd/lib/common/huf.h +340 -0
  28. data/contrib/zstd/{common → lib/common}/mem.h +154 -78
  29. data/contrib/zstd/lib/common/pool.c +344 -0
  30. data/contrib/zstd/lib/common/pool.h +84 -0
  31. data/contrib/zstd/lib/common/threading.c +121 -0
  32. data/contrib/zstd/lib/common/threading.h +155 -0
  33. data/contrib/zstd/{common → lib/common}/xxhash.c +85 -75
  34. data/contrib/zstd/{common → lib/common}/xxhash.h +85 -73
  35. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  36. data/contrib/zstd/lib/common/zstd_errors.h +94 -0
  37. data/contrib/zstd/lib/common/zstd_internal.h +447 -0
  38. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +194 -303
  39. data/contrib/zstd/lib/compress/hist.c +183 -0
  40. data/contrib/zstd/lib/compress/hist.h +75 -0
  41. data/contrib/zstd/lib/compress/huf_compress.c +798 -0
  42. data/contrib/zstd/lib/compress/zstd_compress.c +4278 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1125 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
  49. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  50. data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  52. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  54. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.c +1138 -0
  56. data/contrib/zstd/lib/compress/zstd_lazy.h +67 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.c +619 -0
  58. data/contrib/zstd/lib/compress/zstd_ldm.h +110 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.c +1200 -0
  60. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.c +2143 -0
  62. data/contrib/zstd/lib/compress/zstdmt_compress.h +192 -0
  63. data/contrib/zstd/lib/decompress/huf_decompress.c +1248 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  65. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress.c +1885 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1432 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +59 -0
  69. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +189 -0
  70. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +86 -69
  71. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  73. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.c +1236 -0
  75. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  77. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +5 -5
  78. data/contrib/zstd/lib/dictBuilder/fastcover.c +757 -0
  79. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +437 -347
  80. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  81. data/contrib/zstd/lib/legacy/zstd_legacy.h +415 -0
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +272 -292
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +26 -32
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +162 -392
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +26 -32
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +162 -391
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +27 -33
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +195 -604
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +26 -32
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +300 -575
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +22 -31
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +165 -592
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +54 -67
  94. data/contrib/zstd/lib/legacy/zstd_v07.c +4541 -0
  95. data/contrib/zstd/lib/legacy/zstd_v07.h +187 -0
  96. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  97. data/contrib/zstd/lib/zstd.h +2090 -0
  98. data/ext/depend +2 -0
  99. data/ext/extconf.rb +18 -5
  100. data/ext/extzstd.c +296 -214
  101. data/ext/extzstd.h +81 -36
  102. data/ext/extzstd_nogvls.h +0 -117
  103. data/ext/extzstd_stream.c +622 -0
  104. data/ext/libzstd_conf.h +8 -0
  105. data/ext/zstd_common.c +11 -0
  106. data/ext/zstd_compress.c +15 -0
  107. data/ext/zstd_decompress.c +6 -0
  108. data/ext/zstd_dictbuilder.c +10 -0
  109. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  110. data/ext/zstd_legacy_v01.c +3 -1
  111. data/ext/zstd_legacy_v02.c +3 -1
  112. data/ext/zstd_legacy_v03.c +3 -1
  113. data/ext/zstd_legacy_v04.c +3 -1
  114. data/ext/zstd_legacy_v05.c +3 -1
  115. data/ext/zstd_legacy_v06.c +3 -1
  116. data/ext/zstd_legacy_v07.c +3 -0
  117. data/gemstub.rb +27 -21
  118. data/lib/extzstd.rb +82 -161
  119. data/lib/extzstd/version.rb +1 -1
  120. data/test/test_basic.rb +19 -6
  121. metadata +127 -59
  122. data/contrib/zstd/common/error_private.h +0 -125
  123. data/contrib/zstd/common/error_public.h +0 -77
  124. data/contrib/zstd/common/huf.h +0 -228
  125. data/contrib/zstd/common/zstd.h +0 -475
  126. data/contrib/zstd/common/zstd_common.c +0 -91
  127. data/contrib/zstd/common/zstd_internal.h +0 -238
  128. data/contrib/zstd/compress/huf_compress.c +0 -577
  129. data/contrib/zstd/compress/zbuff_compress.c +0 -327
  130. data/contrib/zstd/compress/zstd_compress.c +0 -3074
  131. data/contrib/zstd/compress/zstd_opt.h +0 -1046
  132. data/contrib/zstd/decompress/huf_decompress.c +0 -894
  133. data/contrib/zstd/decompress/zbuff_decompress.c +0 -294
  134. data/contrib/zstd/decompress/zstd_decompress.c +0 -1362
  135. data/contrib/zstd/dictBuilder/zdict.h +0 -113
  136. data/contrib/zstd/legacy/zstd_legacy.h +0 -140
  137. data/ext/extzstd_buffered.c +0 -265
  138. data/ext/zstd_amalgam.c +0 -18
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #ifndef POOL_H
12
+ #define POOL_H
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+
19
+ #include <stddef.h> /* size_t */
20
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
21
+ #include "../zstd.h"
22
+
23
+ typedef struct POOL_ctx_s POOL_ctx;
24
+
25
+ /*! POOL_create() :
26
+ * Create a thread pool with at most `numThreads` threads.
27
+ * `numThreads` must be at least 1.
28
+ * The maximum number of queued jobs before blocking is `queueSize`.
29
+ * @return : POOL_ctx pointer on success, else NULL.
30
+ */
31
+ POOL_ctx* POOL_create(size_t numThreads, size_t queueSize);
32
+
33
+ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
34
+ ZSTD_customMem customMem);
35
+
36
+ /*! POOL_free() :
37
+ * Free a thread pool returned by POOL_create().
38
+ */
39
+ void POOL_free(POOL_ctx* ctx);
40
+
41
+ /*! POOL_resize() :
42
+ * Expands or shrinks pool's number of threads.
43
+ * This is more efficient than releasing + creating a new context,
44
+ * since it tries to preserve and re-use existing threads.
45
+ * `numThreads` must be at least 1.
46
+ * @return : 0 when resize was successful,
47
+ * !0 (typically 1) if there is an error.
48
+ * note : only numThreads can be resized, queueSize remains unchanged.
49
+ */
50
+ int POOL_resize(POOL_ctx* ctx, size_t numThreads);
51
+
52
+ /*! POOL_sizeof() :
53
+ * @return threadpool memory usage
54
+ * note : compatible with NULL (returns 0 in this case)
55
+ */
56
+ size_t POOL_sizeof(POOL_ctx* ctx);
57
+
58
+ /*! POOL_function :
59
+ * The function type that can be added to a thread pool.
60
+ */
61
+ typedef void (*POOL_function)(void*);
62
+
63
+ /*! POOL_add() :
64
+ * Add the job `function(opaque)` to the thread pool. `ctx` must be valid.
65
+ * Possibly blocks until there is room in the queue.
66
+ * Note : The function may be executed asynchronously,
67
+ * therefore, `opaque` must live until function has been completed.
68
+ */
69
+ void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
70
+
71
+
72
+ /*! POOL_tryAdd() :
73
+ * Add the job `function(opaque)` to thread pool _if_ a worker is available.
74
+ * Returns immediately even if not (does not block).
75
+ * @return : 1 if successful, 0 if not.
76
+ */
77
+ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque);
78
+
79
+
80
+ #if defined (__cplusplus)
81
+ }
82
+ #endif
83
+
84
+ #endif
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Copyright (c) 2016 Tino Reichardt
3
+ * All rights reserved.
4
+ *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
8
+ * This source code is licensed under both the BSD-style license (found in the
9
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
10
+ * in the COPYING file in the root directory of this source tree).
11
+ * You may select, at your option, one of the above-listed licenses.
12
+ */
13
+
14
+ /**
15
+ * This file will hold wrapper for systems, which do not support pthreads
16
+ */
17
+
18
+ #include "threading.h"
19
+
20
+ /* create fake symbol to avoid empty translation unit warning */
21
+ int g_ZSTD_threading_useless_symbol;
22
+
23
+ #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24
+
25
+ /**
26
+ * Windows minimalist Pthread Wrapper, based on :
27
+ * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
28
+ */
29
+
30
+
31
+ /* === Dependencies === */
32
+ #include <process.h>
33
+ #include <errno.h>
34
+
35
+
36
+ /* === Implementation === */
37
+
38
+ static unsigned __stdcall worker(void *arg)
39
+ {
40
+ ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
41
+ thread->arg = thread->start_routine(thread->arg);
42
+ return 0;
43
+ }
44
+
45
+ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
46
+ void* (*start_routine) (void*), void* arg)
47
+ {
48
+ (void)unused;
49
+ thread->arg = arg;
50
+ thread->start_routine = start_routine;
51
+ thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
52
+
53
+ if (!thread->handle)
54
+ return errno;
55
+ else
56
+ return 0;
57
+ }
58
+
59
+ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
60
+ {
61
+ DWORD result;
62
+
63
+ if (!thread.handle) return 0;
64
+
65
+ result = WaitForSingleObject(thread.handle, INFINITE);
66
+ switch (result) {
67
+ case WAIT_OBJECT_0:
68
+ if (value_ptr) *value_ptr = thread.arg;
69
+ return 0;
70
+ case WAIT_ABANDONED:
71
+ return EINVAL;
72
+ default:
73
+ return GetLastError();
74
+ }
75
+ }
76
+
77
+ #endif /* ZSTD_MULTITHREAD */
78
+
79
+ #if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
80
+
81
+ #include <stdlib.h>
82
+
83
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
84
+ {
85
+ *mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
86
+ if (!*mutex)
87
+ return 1;
88
+ return pthread_mutex_init(*mutex, attr);
89
+ }
90
+
91
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
92
+ {
93
+ if (!*mutex)
94
+ return 0;
95
+ {
96
+ int const ret = pthread_mutex_destroy(*mutex);
97
+ free(*mutex);
98
+ return ret;
99
+ }
100
+ }
101
+
102
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
103
+ {
104
+ *cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
105
+ if (!*cond)
106
+ return 1;
107
+ return pthread_cond_init(*cond, attr);
108
+ }
109
+
110
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
111
+ {
112
+ if (!*cond)
113
+ return 0;
114
+ {
115
+ int const ret = pthread_cond_destroy(*cond);
116
+ free(*cond);
117
+ return ret;
118
+ }
119
+ }
120
+
121
+ #endif
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Copyright (c) 2016 Tino Reichardt
3
+ * All rights reserved.
4
+ *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
8
+ * This source code is licensed under both the BSD-style license (found in the
9
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
10
+ * in the COPYING file in the root directory of this source tree).
11
+ * You may select, at your option, one of the above-listed licenses.
12
+ */
13
+
14
+ #ifndef THREADING_H_938743
15
+ #define THREADING_H_938743
16
+
17
+ #include "debug.h"
18
+
19
+ #if defined (__cplusplus)
20
+ extern "C" {
21
+ #endif
22
+
23
+ #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24
+
25
+ /**
26
+ * Windows minimalist Pthread Wrapper, based on :
27
+ * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
28
+ */
29
+ #ifdef WINVER
30
+ # undef WINVER
31
+ #endif
32
+ #define WINVER 0x0600
33
+
34
+ #ifdef _WIN32_WINNT
35
+ # undef _WIN32_WINNT
36
+ #endif
37
+ #define _WIN32_WINNT 0x0600
38
+
39
+ #ifndef WIN32_LEAN_AND_MEAN
40
+ # define WIN32_LEAN_AND_MEAN
41
+ #endif
42
+
43
+ #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
44
+ #include <windows.h>
45
+ #undef ERROR
46
+ #define ERROR(name) ZSTD_ERROR(name)
47
+
48
+
49
+ /* mutex */
50
+ #define ZSTD_pthread_mutex_t CRITICAL_SECTION
51
+ #define ZSTD_pthread_mutex_init(a, b) ((void)(b), InitializeCriticalSection((a)), 0)
52
+ #define ZSTD_pthread_mutex_destroy(a) DeleteCriticalSection((a))
53
+ #define ZSTD_pthread_mutex_lock(a) EnterCriticalSection((a))
54
+ #define ZSTD_pthread_mutex_unlock(a) LeaveCriticalSection((a))
55
+
56
+ /* condition variable */
57
+ #define ZSTD_pthread_cond_t CONDITION_VARIABLE
58
+ #define ZSTD_pthread_cond_init(a, b) ((void)(b), InitializeConditionVariable((a)), 0)
59
+ #define ZSTD_pthread_cond_destroy(a) ((void)(a))
60
+ #define ZSTD_pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE)
61
+ #define ZSTD_pthread_cond_signal(a) WakeConditionVariable((a))
62
+ #define ZSTD_pthread_cond_broadcast(a) WakeAllConditionVariable((a))
63
+
64
+ /* ZSTD_pthread_create() and ZSTD_pthread_join() */
65
+ typedef struct {
66
+ HANDLE handle;
67
+ void* (*start_routine)(void*);
68
+ void* arg;
69
+ } ZSTD_pthread_t;
70
+
71
+ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
72
+ void* (*start_routine) (void*), void* arg);
73
+
74
+ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
75
+
76
+ /**
77
+ * add here more wrappers as required
78
+ */
79
+
80
+
81
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
82
+ /* === POSIX Systems === */
83
+ # include <pthread.h>
84
+
85
+ #if DEBUGLEVEL < 1
86
+
87
+ #define ZSTD_pthread_mutex_t pthread_mutex_t
88
+ #define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
89
+ #define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
90
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock((a))
91
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock((a))
92
+
93
+ #define ZSTD_pthread_cond_t pthread_cond_t
94
+ #define ZSTD_pthread_cond_init(a, b) pthread_cond_init((a), (b))
95
+ #define ZSTD_pthread_cond_destroy(a) pthread_cond_destroy((a))
96
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait((a), (b))
97
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal((a))
98
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast((a))
99
+
100
+ #define ZSTD_pthread_t pthread_t
101
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
102
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
103
+
104
+ #else /* DEBUGLEVEL >= 1 */
105
+
106
+ /* Debug implementation of threading.
107
+ * In this implementation we use pointers for mutexes and condition variables.
108
+ * This way, if we forget to init/destroy them the program will crash or ASAN
109
+ * will report leaks.
110
+ */
111
+
112
+ #define ZSTD_pthread_mutex_t pthread_mutex_t*
113
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr);
114
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex);
115
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock(*(a))
116
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock(*(a))
117
+
118
+ #define ZSTD_pthread_cond_t pthread_cond_t*
119
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr);
120
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond);
121
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait(*(a), *(b))
122
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal(*(a))
123
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast(*(a))
124
+
125
+ #define ZSTD_pthread_t pthread_t
126
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
127
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
128
+
129
+ #endif
130
+
131
+ #else /* ZSTD_MULTITHREAD not defined */
132
+ /* No multithreading support */
133
+
134
+ typedef int ZSTD_pthread_mutex_t;
135
+ #define ZSTD_pthread_mutex_init(a, b) ((void)(a), (void)(b), 0)
136
+ #define ZSTD_pthread_mutex_destroy(a) ((void)(a))
137
+ #define ZSTD_pthread_mutex_lock(a) ((void)(a))
138
+ #define ZSTD_pthread_mutex_unlock(a) ((void)(a))
139
+
140
+ typedef int ZSTD_pthread_cond_t;
141
+ #define ZSTD_pthread_cond_init(a, b) ((void)(a), (void)(b), 0)
142
+ #define ZSTD_pthread_cond_destroy(a) ((void)(a))
143
+ #define ZSTD_pthread_cond_wait(a, b) ((void)(a), (void)(b))
144
+ #define ZSTD_pthread_cond_signal(a) ((void)(a))
145
+ #define ZSTD_pthread_cond_broadcast(a) ((void)(a))
146
+
147
+ /* do not use ZSTD_pthread_t */
148
+
149
+ #endif /* ZSTD_MULTITHREAD */
150
+
151
+ #if defined (__cplusplus)
152
+ }
153
+ #endif
154
+
155
+ #endif /* THREADING_H_938743 */
@@ -1,35 +1,15 @@
1
1
  /*
2
- * xxHash - Fast Hash algorithm
3
- * Copyright (C) 2012-2016, Yann Collet
4
- *
5
- * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are
9
- * met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * * Redistributions in binary form must reproduce the above
14
- * copyright notice, this list of conditions and the following disclaimer
15
- * in the documentation and/or other materials provided with the
16
- * distribution.
17
- *
18
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- *
30
- * You can contact the author at :
31
- * - xxHash homepage: http://www.xxhash.com
32
- * - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Fast Hash algorithm
3
+ * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - xxHash homepage: http://www.xxhash.com
7
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  */
34
14
 
35
15
 
@@ -52,8 +32,9 @@
52
32
  #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
53
33
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
54
34
  # define XXH_FORCE_MEMORY_ACCESS 2
55
- # elif defined(__INTEL_COMPILER) || \
56
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
35
+ # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
36
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) || \
37
+ defined(__ICCARM__)
57
38
  # define XXH_FORCE_MEMORY_ACCESS 1
58
39
  # endif
59
40
  #endif
@@ -66,10 +47,10 @@
66
47
  /* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
67
48
 
68
49
  /*!XXH_FORCE_NATIVE_FORMAT :
69
- * By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
50
+ * By default, xxHash library provides endian-independent Hash values, based on little-endian convention.
70
51
  * Results are therefore identical for little-endian and big-endian CPU.
71
52
  * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
72
- * Should endian-independance be of no importance for your application, you may set the #define below to 1,
53
+ * Should endian-independence be of no importance for your application, you may set the #define below to 1,
73
54
  * to improve speed for Big-endian CPU.
74
55
  * This option has no impact on Little_Endian CPU.
75
56
  */
@@ -98,32 +79,41 @@
98
79
  /* Modify the local functions below should you wish to use some other memory routines */
99
80
  /* for malloc(), free() */
100
81
  #include <stdlib.h>
82
+ #include <stddef.h> /* size_t */
101
83
  static void* XXH_malloc(size_t s) { return malloc(s); }
102
84
  static void XXH_free (void* p) { free(p); }
103
85
  /* for memcpy() */
104
86
  #include <string.h>
105
87
  static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
106
88
 
107
- #define XXH_STATIC_LINKING_ONLY
89
+ #ifndef XXH_STATIC_LINKING_ONLY
90
+ # define XXH_STATIC_LINKING_ONLY
91
+ #endif
108
92
  #include "xxhash.h"
109
93
 
110
94
 
111
95
  /* *************************************
112
96
  * Compiler Specific Options
113
97
  ***************************************/
114
- #ifdef _MSC_VER /* Visual Studio */
115
- # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
116
- # define FORCE_INLINE static __forceinline
98
+ #if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
99
+ # define INLINE_KEYWORD inline
117
100
  #else
118
- # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
119
- # ifdef __GNUC__
120
- # define FORCE_INLINE static inline __attribute__((always_inline))
121
- # else
122
- # define FORCE_INLINE static inline
123
- # endif
124
- # else
125
- # define FORCE_INLINE static
126
- # endif /* __STDC_VERSION__ */
101
+ # define INLINE_KEYWORD
102
+ #endif
103
+
104
+ #if defined(__GNUC__) || defined(__ICCARM__)
105
+ # define FORCE_INLINE_ATTR __attribute__((always_inline))
106
+ #elif defined(_MSC_VER)
107
+ # define FORCE_INLINE_ATTR __forceinline
108
+ #else
109
+ # define FORCE_INLINE_ATTR
110
+ #endif
111
+
112
+ #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
113
+
114
+
115
+ #ifdef _MSC_VER
116
+ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
127
117
  #endif
128
118
 
129
119
 
@@ -132,7 +122,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
132
122
  ***************************************/
133
123
  #ifndef MEM_MODULE
134
124
  # define MEM_MODULE
135
- # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
125
+ # if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
136
126
  # include <stdint.h>
137
127
  typedef uint8_t BYTE;
138
128
  typedef uint16_t U16;
@@ -144,7 +134,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
144
134
  typedef unsigned short U16;
145
135
  typedef unsigned int U32;
146
136
  typedef signed int S32;
147
- typedef unsigned long long U64;
137
+ typedef unsigned long long U64; /* if your compiler doesn't support unsigned long long, replace by another 64-bit type here. Note that xxhash.h will also need to be updated. */
148
138
  # endif
149
139
  #endif
150
140
 
@@ -197,7 +187,12 @@ static U64 XXH_read64(const void* memPtr)
197
187
  # define XXH_rotl32(x,r) _rotl(x,r)
198
188
  # define XXH_rotl64(x,r) _rotl64(x,r)
199
189
  #else
190
+ #if defined(__ICCARM__)
191
+ # include <intrinsics.h>
192
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
193
+ #else
200
194
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
195
+ #endif
201
196
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
202
197
  #endif
203
198
 
@@ -246,7 +241,7 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
246
241
  *****************************/
247
242
  typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
248
243
 
249
- FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
244
+ FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
250
245
  {
251
246
  if (align==XXH_unaligned)
252
247
  return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
@@ -254,7 +249,7 @@ FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_a
254
249
  return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
255
250
  }
256
251
 
257
- FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
252
+ FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
258
253
  {
259
254
  return XXH_readLE32_align(ptr, endian, XXH_unaligned);
260
255
  }
@@ -264,7 +259,7 @@ static U32 XXH_readBE32(const void* ptr)
264
259
  return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
265
260
  }
266
261
 
267
- FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
262
+ FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
268
263
  {
269
264
  if (align==XXH_unaligned)
270
265
  return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
@@ -272,7 +267,7 @@ FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_a
272
267
  return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
273
268
  }
274
269
 
275
- FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
270
+ FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
276
271
  {
277
272
  return XXH_readLE64_align(ptr, endian, XXH_unaligned);
278
273
  }
@@ -307,6 +302,20 @@ static const U64 PRIME64_5 = 2870177450012600261ULL;
307
302
  XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
308
303
 
309
304
 
305
+ /* **************************
306
+ * Utils
307
+ ****************************/
308
+ XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
309
+ {
310
+ memcpy(dstState, srcState, sizeof(*dstState));
311
+ }
312
+
313
+ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
314
+ {
315
+ memcpy(dstState, srcState, sizeof(*dstState));
316
+ }
317
+
318
+
310
319
  /* ***************************
311
320
  * Simple Hash Functions
312
321
  *****************************/
@@ -319,7 +328,7 @@ static U32 XXH32_round(U32 seed, U32 input)
319
328
  return seed;
320
329
  }
321
330
 
322
- FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
331
+ FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
323
332
  {
324
333
  const BYTE* p = (const BYTE*)input;
325
334
  const BYTE* bEnd = p + len;
@@ -419,7 +428,7 @@ static U64 XXH64_mergeRound(U64 acc, U64 val)
419
428
  return acc;
420
429
  }
421
430
 
422
- FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
431
+ FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
423
432
  {
424
433
  const BYTE* p = (const BYTE*)input;
425
434
  const BYTE* const bEnd = p + len;
@@ -545,8 +554,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
545
554
  XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
546
555
  {
547
556
  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
548
- memset(&state, 0, sizeof(state));
549
- state.seed = seed;
557
+ memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
550
558
  state.v1 = seed + PRIME32_1 + PRIME32_2;
551
559
  state.v2 = seed + PRIME32_2;
552
560
  state.v3 = seed + 0;
@@ -559,8 +567,7 @@ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int s
559
567
  XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
560
568
  {
561
569
  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
562
- memset(&state, 0, sizeof(state));
563
- state.seed = seed;
570
+ memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
564
571
  state.v1 = seed + PRIME64_1 + PRIME64_2;
565
572
  state.v2 = seed + PRIME64_2;
566
573
  state.v3 = seed + 0;
@@ -570,7 +577,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long
570
577
  }
571
578
 
572
579
 
573
- FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
580
+ FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
574
581
  {
575
582
  const BYTE* p = (const BYTE*)input;
576
583
  const BYTE* const bEnd = p + len;
@@ -579,11 +586,12 @@ FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void
579
586
  if (input==NULL) return XXH_ERROR;
580
587
  #endif
581
588
 
582
- state->total_len += len;
589
+ state->total_len_32 += (unsigned)len;
590
+ state->large_len |= (len>=16) | (state->total_len_32>=16);
583
591
 
584
592
  if (state->memsize + len < 16) { /* fill in tmp buffer */
585
593
  XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
586
- state->memsize += (U32)len;
594
+ state->memsize += (unsigned)len;
587
595
  return XXH_OK;
588
596
  }
589
597
 
@@ -620,8 +628,8 @@ FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void
620
628
  }
621
629
 
622
630
  if (p < bEnd) {
623
- XXH_memcpy(state->mem32, p, bEnd-p);
624
- state->memsize = (int)(bEnd-p);
631
+ XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
632
+ state->memsize = (unsigned)(bEnd-p);
625
633
  }
626
634
 
627
635
  return XXH_OK;
@@ -639,19 +647,19 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void*
639
647
 
640
648
 
641
649
 
642
- FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
650
+ FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
643
651
  {
644
652
  const BYTE * p = (const BYTE*)state->mem32;
645
653
  const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
646
654
  U32 h32;
647
655
 
648
- if (state->total_len >= 16) {
656
+ if (state->large_len) {
649
657
  h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
650
658
  } else {
651
- h32 = state->seed + PRIME32_5;
659
+ h32 = state->v3 /* == seed */ + PRIME32_5;
652
660
  }
653
661
 
654
- h32 += (U32) state->total_len;
662
+ h32 += state->total_len_32;
655
663
 
656
664
  while (p+4<=bEnd) {
657
665
  h32 += XXH_readLE32(p, endian) * PRIME32_3;
@@ -689,7 +697,7 @@ XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)
689
697
 
690
698
  /* **** XXH64 **** */
691
699
 
692
- FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
700
+ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
693
701
  {
694
702
  const BYTE* p = (const BYTE*)input;
695
703
  const BYTE* const bEnd = p + len;
@@ -701,7 +709,9 @@ FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void
701
709
  state->total_len += len;
702
710
 
703
711
  if (state->memsize + len < 32) { /* fill in tmp buffer */
704
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
712
+ if (input != NULL) {
713
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
714
+ }
705
715
  state->memsize += (U32)len;
706
716
  return XXH_OK;
707
717
  }
@@ -737,8 +747,8 @@ FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void
737
747
  }
738
748
 
739
749
  if (p < bEnd) {
740
- XXH_memcpy(state->mem64, p, bEnd-p);
741
- state->memsize = (int)(bEnd-p);
750
+ XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
751
+ state->memsize = (unsigned)(bEnd-p);
742
752
  }
743
753
 
744
754
  return XXH_OK;
@@ -756,7 +766,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void*
756
766
 
757
767
 
758
768
 
759
- FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
769
+ FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
760
770
  {
761
771
  const BYTE * p = (const BYTE*)state->mem64;
762
772
  const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
@@ -774,7 +784,7 @@ FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess
774
784
  h64 = XXH64_mergeRound(h64, v3);
775
785
  h64 = XXH64_mergeRound(h64, v4);
776
786
  } else {
777
- h64 = state->seed + PRIME64_5;
787
+ h64 = state->v3 + PRIME64_5;
778
788
  }
779
789
 
780
790
  h64 += (U64) state->total_len;