redis-server 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. data/LICENSE +38 -0
  2. data/README.md +33 -0
  3. data/bin/redis +114 -0
  4. data/redis/Makefile +5 -0
  5. data/redis/extconf.rb +3 -0
  6. data/redis/redis-2.2.11/00-RELEASENOTES +199 -0
  7. data/redis/redis-2.2.11/BUGS +1 -0
  8. data/redis/redis-2.2.11/CONTRIBUTING +13 -0
  9. data/redis/redis-2.2.11/COPYING +10 -0
  10. data/redis/redis-2.2.11/Changelog +1032 -0
  11. data/redis/redis-2.2.11/INSTALL +30 -0
  12. data/redis/redis-2.2.11/Makefile +22 -0
  13. data/redis/redis-2.2.11/README +83 -0
  14. data/redis/redis-2.2.11/TODO +4 -0
  15. data/redis/redis-2.2.11/client-libraries/README +11 -0
  16. data/redis/redis-2.2.11/deps/hiredis/COPYING +10 -0
  17. data/redis/redis-2.2.11/deps/hiredis/Makefile +115 -0
  18. data/redis/redis-2.2.11/deps/hiredis/README.md +311 -0
  19. data/redis/redis-2.2.11/deps/hiredis/TODO +2 -0
  20. data/redis/redis-2.2.11/deps/hiredis/adapters/ae.h +95 -0
  21. data/redis/redis-2.2.11/deps/hiredis/adapters/libev.h +113 -0
  22. data/redis/redis-2.2.11/deps/hiredis/adapters/libevent.h +76 -0
  23. data/redis/redis-2.2.11/deps/hiredis/async.c +321 -0
  24. data/redis/redis-2.2.11/deps/hiredis/async.h +112 -0
  25. data/redis/redis-2.2.11/deps/hiredis/example-ae.c +53 -0
  26. data/redis/redis-2.2.11/deps/hiredis/example-libev.c +47 -0
  27. data/redis/redis-2.2.11/deps/hiredis/example-libevent.c +48 -0
  28. data/redis/redis-2.2.11/deps/hiredis/example.c +67 -0
  29. data/redis/redis-2.2.11/deps/hiredis/fmacros.h +15 -0
  30. data/redis/redis-2.2.11/deps/hiredis/hiredis.c +1058 -0
  31. data/redis/redis-2.2.11/deps/hiredis/hiredis.h +170 -0
  32. data/redis/redis-2.2.11/deps/hiredis/net.c +170 -0
  33. data/redis/redis-2.2.11/deps/hiredis/net.h +43 -0
  34. data/redis/redis-2.2.11/deps/hiredis/sds.c +479 -0
  35. data/redis/redis-2.2.11/deps/hiredis/sds.h +77 -0
  36. data/redis/redis-2.2.11/deps/hiredis/test.c +479 -0
  37. data/redis/redis-2.2.11/deps/hiredis/util.h +40 -0
  38. data/redis/redis-2.2.11/deps/linenoise/Makefile +10 -0
  39. data/redis/redis-2.2.11/deps/linenoise/README.markdown +45 -0
  40. data/redis/redis-2.2.11/deps/linenoise/example.c +27 -0
  41. data/redis/redis-2.2.11/deps/linenoise/linenoise.c +609 -0
  42. data/redis/redis-2.2.11/deps/linenoise/linenoise.h +55 -0
  43. data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER +214 -0
  44. data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER-2 +343 -0
  45. data/redis/redis-2.2.11/doc/AppendCommand.html +48 -0
  46. data/redis/redis-2.2.11/doc/AppendOnlyFileHowto.html +41 -0
  47. data/redis/redis-2.2.11/doc/AuthCommand.html +39 -0
  48. data/redis/redis-2.2.11/doc/Benchmarks.html +129 -0
  49. data/redis/redis-2.2.11/doc/BgrewriteaofCommand.html +41 -0
  50. data/redis/redis-2.2.11/doc/BgsaveCommand.html +39 -0
  51. data/redis/redis-2.2.11/doc/BlpopCommand.html +51 -0
  52. data/redis/redis-2.2.11/doc/BrpoplpushCommand.html +39 -0
  53. data/redis/redis-2.2.11/doc/CommandReference.html +47 -0
  54. data/redis/redis-2.2.11/doc/Comparisons.html +42 -0
  55. data/redis/redis-2.2.11/doc/ConfigCommand.html +76 -0
  56. data/redis/redis-2.2.11/doc/Configuration.html +38 -0
  57. data/redis/redis-2.2.11/doc/ConnectionHandlingSidebar.html +36 -0
  58. data/redis/redis-2.2.11/doc/ControlCommandsSidebar.html +36 -0
  59. data/redis/redis-2.2.11/doc/Credits.html +38 -0
  60. data/redis/redis-2.2.11/doc/DbsizeCommand.html +38 -0
  61. data/redis/redis-2.2.11/doc/DelCommand.html +41 -0
  62. data/redis/redis-2.2.11/doc/DesignPatterns.html +37 -0
  63. data/redis/redis-2.2.11/doc/EventLibray.html +44 -0
  64. data/redis/redis-2.2.11/doc/ExistsCommand.html +42 -0
  65. data/redis/redis-2.2.11/doc/ExpireCommand.html +96 -0
  66. data/redis/redis-2.2.11/doc/FAQ.html +70 -0
  67. data/redis/redis-2.2.11/doc/Features.html +38 -0
  68. data/redis/redis-2.2.11/doc/FlushallCommand.html +39 -0
  69. data/redis/redis-2.2.11/doc/FlushdbCommand.html +39 -0
  70. data/redis/redis-2.2.11/doc/FromSqlToDataStructures.html +37 -0
  71. data/redis/redis-2.2.11/doc/GenericCommandsSidebar.html +36 -0
  72. data/redis/redis-2.2.11/doc/GetCommand.html +39 -0
  73. data/redis/redis-2.2.11/doc/GetbitCommand.html +39 -0
  74. data/redis/redis-2.2.11/doc/GetsetCommand.html +38 -0
  75. data/redis/redis-2.2.11/doc/HackingStrings.html +83 -0
  76. data/redis/redis-2.2.11/doc/HashCommandsSidebar.html +36 -0
  77. data/redis/redis-2.2.11/doc/Hashes.html +37 -0
  78. data/redis/redis-2.2.11/doc/HdelCommand.html +39 -0
  79. data/redis/redis-2.2.11/doc/HexistsCommand.html +39 -0
  80. data/redis/redis-2.2.11/doc/HgetCommand.html +39 -0
  81. data/redis/redis-2.2.11/doc/HgetallCommand.html +40 -0
  82. data/redis/redis-2.2.11/doc/HincrbyCommand.html +45 -0
  83. data/redis/redis-2.2.11/doc/HlenCommand.html +38 -0
  84. data/redis/redis-2.2.11/doc/HmgetCommand.html +40 -0
  85. data/redis/redis-2.2.11/doc/HmsetCommand.html +40 -0
  86. data/redis/redis-2.2.11/doc/HsetCommand.html +40 -0
  87. data/redis/redis-2.2.11/doc/HsetnxCommand.html +41 -0
  88. data/redis/redis-2.2.11/doc/IncrCommand.html +43 -0
  89. data/redis/redis-2.2.11/doc/InfoCommand.html +48 -0
  90. data/redis/redis-2.2.11/doc/IntroductionToRedisDataTypes.html +152 -0
  91. data/redis/redis-2.2.11/doc/KeysCommand.html +43 -0
  92. data/redis/redis-2.2.11/doc/LastsaveCommand.html +39 -0
  93. data/redis/redis-2.2.11/doc/LindexCommand.html +40 -0
  94. data/redis/redis-2.2.11/doc/ListCommandsSidebar.html +36 -0
  95. data/redis/redis-2.2.11/doc/Lists.html +42 -0
  96. data/redis/redis-2.2.11/doc/LlenCommand.html +41 -0
  97. data/redis/redis-2.2.11/doc/LpopCommand.html +41 -0
  98. data/redis/redis-2.2.11/doc/LrangeCommand.html +47 -0
  99. data/redis/redis-2.2.11/doc/LremCommand.html +41 -0
  100. data/redis/redis-2.2.11/doc/LsetCommand.html +38 -0
  101. data/redis/redis-2.2.11/doc/LtrimCommand.html +47 -0
  102. data/redis/redis-2.2.11/doc/MgetCommand.html +52 -0
  103. data/redis/redis-2.2.11/doc/MonitorCommand.html +63 -0
  104. data/redis/redis-2.2.11/doc/MoveCommand.html +42 -0
  105. data/redis/redis-2.2.11/doc/MsetCommand.html +44 -0
  106. data/redis/redis-2.2.11/doc/MultiExecCommand.html +166 -0
  107. data/redis/redis-2.2.11/doc/NonexistentCommands.html +51 -0
  108. data/redis/redis-2.2.11/doc/ObjectHashMappers.html +39 -0
  109. data/redis/redis-2.2.11/doc/Pipelining.html +36 -0
  110. data/redis/redis-2.2.11/doc/ProgrammingExamples.html +38 -0
  111. data/redis/redis-2.2.11/doc/ProtocolSpecification.html +137 -0
  112. data/redis/redis-2.2.11/doc/PublishSubscribe.html +115 -0
  113. data/redis/redis-2.2.11/doc/QuickStart.html +68 -0
  114. data/redis/redis-2.2.11/doc/QuitCommand.html +38 -0
  115. data/redis/redis-2.2.11/doc/README.html +119 -0
  116. data/redis/redis-2.2.11/doc/RandomkeyCommand.html +39 -0
  117. data/redis/redis-2.2.11/doc/Redis0100ChangeLog.html +67 -0
  118. data/redis/redis-2.2.11/doc/Redis0900ChangeLog.html +56 -0
  119. data/redis/redis-2.2.11/doc/RedisBigData.html +61 -0
  120. data/redis/redis-2.2.11/doc/RedisCLI.html +37 -0
  121. data/redis/redis-2.2.11/doc/RedisEventLibrary.html +70 -0
  122. data/redis/redis-2.2.11/doc/RedisGuides.html +37 -0
  123. data/redis/redis-2.2.11/doc/RedisInternals.html +38 -0
  124. data/redis/redis-2.2.11/doc/RedisPipelining.html +93 -0
  125. data/redis/redis-2.2.11/doc/RedisStatus.html +56 -0
  126. data/redis/redis-2.2.11/doc/Redis_1_2_0_Changelog.html +40 -0
  127. data/redis/redis-2.2.11/doc/Redis_2_0_0_Changelog.html +62 -0
  128. data/redis/redis-2.2.11/doc/Redis_2_0_Whats_new.html +59 -0
  129. data/redis/redis-2.2.11/doc/RenameCommand.html +39 -0
  130. data/redis/redis-2.2.11/doc/RenamenxCommand.html +42 -0
  131. data/redis/redis-2.2.11/doc/ReplicationHowto.html +43 -0
  132. data/redis/redis-2.2.11/doc/ReplyTypes.html +42 -0
  133. data/redis/redis-2.2.11/doc/RoadMap.html +38 -0
  134. data/redis/redis-2.2.11/doc/RpoplpushCommand.html +44 -0
  135. data/redis/redis-2.2.11/doc/RpushCommand.html +40 -0
  136. data/redis/redis-2.2.11/doc/SaddCommand.html +41 -0
  137. data/redis/redis-2.2.11/doc/SaveCommand.html +39 -0
  138. data/redis/redis-2.2.11/doc/ScardCommand.html +41 -0
  139. data/redis/redis-2.2.11/doc/SdiffCommand.html +45 -0
  140. data/redis/redis-2.2.11/doc/SdiffstoreCommand.html +38 -0
  141. data/redis/redis-2.2.11/doc/SelectCommand.html +39 -0
  142. data/redis/redis-2.2.11/doc/SetCommand.html +39 -0
  143. data/redis/redis-2.2.11/doc/SetCommandsSidebar.html +36 -0
  144. data/redis/redis-2.2.11/doc/SetbitCommand.html +45 -0
  145. data/redis/redis-2.2.11/doc/SetexCommand.html +42 -0
  146. data/redis/redis-2.2.11/doc/SetnxCommand.html +51 -0
  147. data/redis/redis-2.2.11/doc/SetrangeCommand.html +58 -0
  148. data/redis/redis-2.2.11/doc/Sets.html +36 -0
  149. data/redis/redis-2.2.11/doc/ShutdownCommand.html +39 -0
  150. data/redis/redis-2.2.11/doc/SideBar.html +36 -0
  151. data/redis/redis-2.2.11/doc/SinterCommand.html +40 -0
  152. data/redis/redis-2.2.11/doc/SinterstoreCommand.html +39 -0
  153. data/redis/redis-2.2.11/doc/SismemberCommand.html +42 -0
  154. data/redis/redis-2.2.11/doc/SlaveofCommand.html +41 -0
  155. data/redis/redis-2.2.11/doc/SmembersCommand.html +38 -0
  156. data/redis/redis-2.2.11/doc/SmoveCommand.html +44 -0
  157. data/redis/redis-2.2.11/doc/SortCommand.html +75 -0
  158. data/redis/redis-2.2.11/doc/SortedSetCommandsSidebar.html +36 -0
  159. data/redis/redis-2.2.11/doc/SortedSets.html +36 -0
  160. data/redis/redis-2.2.11/doc/Speed.html +38 -0
  161. data/redis/redis-2.2.11/doc/SponsorshipHistory.html +38 -0
  162. data/redis/redis-2.2.11/doc/SpopCommand.html +40 -0
  163. data/redis/redis-2.2.11/doc/SrandmemberCommand.html +40 -0
  164. data/redis/redis-2.2.11/doc/SremCommand.html +42 -0
  165. data/redis/redis-2.2.11/doc/StringCommandsSidebar.html +36 -0
  166. data/redis/redis-2.2.11/doc/Strings.html +37 -0
  167. data/redis/redis-2.2.11/doc/StrlenCommand.html +39 -0
  168. data/redis/redis-2.2.11/doc/SubstrCommand.html +52 -0
  169. data/redis/redis-2.2.11/doc/SunionCommand.html +40 -0
  170. data/redis/redis-2.2.11/doc/SunionstoreCommand.html +38 -0
  171. data/redis/redis-2.2.11/doc/SupportedLanguages.html +60 -0
  172. data/redis/redis-2.2.11/doc/SupportedPlatforms.html +37 -0
  173. data/redis/redis-2.2.11/doc/TemplateCommand.html +38 -0
  174. data/redis/redis-2.2.11/doc/TtlCommand.html +38 -0
  175. data/redis/redis-2.2.11/doc/TwitterAlikeExample.html +250 -0
  176. data/redis/redis-2.2.11/doc/TypeCommand.html +46 -0
  177. data/redis/redis-2.2.11/doc/UnstableSource.html +39 -0
  178. data/redis/redis-2.2.11/doc/VirtualMemorySpecification.html +156 -0
  179. data/redis/redis-2.2.11/doc/VirtualMemoryUserGuide.html +66 -0
  180. data/redis/redis-2.2.11/doc/ZaddCommand.html +43 -0
  181. data/redis/redis-2.2.11/doc/ZcardCommand.html +41 -0
  182. data/redis/redis-2.2.11/doc/ZincrbyCommand.html +42 -0
  183. data/redis/redis-2.2.11/doc/ZrangeCommand.html +42 -0
  184. data/redis/redis-2.2.11/doc/ZrangebyscoreCommand.html +77 -0
  185. data/redis/redis-2.2.11/doc/ZrankCommand.html +43 -0
  186. data/redis/redis-2.2.11/doc/ZremCommand.html +42 -0
  187. data/redis/redis-2.2.11/doc/ZremrangebyrankCommand.html +39 -0
  188. data/redis/redis-2.2.11/doc/ZremrangebyscoreCommand.html +39 -0
  189. data/redis/redis-2.2.11/doc/ZscoreCommand.html +41 -0
  190. data/redis/redis-2.2.11/doc/ZunionCommand.html +42 -0
  191. data/redis/redis-2.2.11/doc/ZunionstoreCommand.html +43 -0
  192. data/redis/redis-2.2.11/doc/index.html +43 -0
  193. data/redis/redis-2.2.11/doc/redis.png +0 -0
  194. data/redis/redis-2.2.11/doc/style.css +25 -0
  195. data/redis/redis-2.2.11/redis.conf +417 -0
  196. data/redis/redis-2.2.11/src/Makefile +177 -0
  197. data/redis/redis-2.2.11/src/adlist.c +325 -0
  198. data/redis/redis-2.2.11/src/adlist.h +92 -0
  199. data/redis/redis-2.2.11/src/ae.c +390 -0
  200. data/redis/redis-2.2.11/src/ae.h +117 -0
  201. data/redis/redis-2.2.11/src/ae_epoll.c +91 -0
  202. data/redis/redis-2.2.11/src/ae_kqueue.c +93 -0
  203. data/redis/redis-2.2.11/src/ae_select.c +72 -0
  204. data/redis/redis-2.2.11/src/anet.c +347 -0
  205. data/redis/redis-2.2.11/src/anet.h +57 -0
  206. data/redis/redis-2.2.11/src/aof.c +675 -0
  207. data/redis/redis-2.2.11/src/config.c +627 -0
  208. data/redis/redis-2.2.11/src/config.h +64 -0
  209. data/redis/redis-2.2.11/src/db.c +543 -0
  210. data/redis/redis-2.2.11/src/debug.c +314 -0
  211. data/redis/redis-2.2.11/src/dict.c +721 -0
  212. data/redis/redis-2.2.11/src/dict.h +156 -0
  213. data/redis/redis-2.2.11/src/fmacros.h +15 -0
  214. data/redis/redis-2.2.11/src/help.h +638 -0
  215. data/redis/redis-2.2.11/src/intset.c +422 -0
  216. data/redis/redis-2.2.11/src/intset.h +19 -0
  217. data/redis/redis-2.2.11/src/lzf.h +100 -0
  218. data/redis/redis-2.2.11/src/lzfP.h +159 -0
  219. data/redis/redis-2.2.11/src/lzf_c.c +295 -0
  220. data/redis/redis-2.2.11/src/lzf_d.c +150 -0
  221. data/redis/redis-2.2.11/src/mkreleasehdr.sh +9 -0
  222. data/redis/redis-2.2.11/src/multi.c +268 -0
  223. data/redis/redis-2.2.11/src/networking.c +899 -0
  224. data/redis/redis-2.2.11/src/object.c +484 -0
  225. data/redis/redis-2.2.11/src/pqsort.c +197 -0
  226. data/redis/redis-2.2.11/src/pqsort.h +15 -0
  227. data/redis/redis-2.2.11/src/pubsub.c +267 -0
  228. data/redis/redis-2.2.11/src/rdb.c +1020 -0
  229. data/redis/redis-2.2.11/src/redis-benchmark.c +530 -0
  230. data/redis/redis-2.2.11/src/redis-check-aof.c +185 -0
  231. data/redis/redis-2.2.11/src/redis-check-dump.c +681 -0
  232. data/redis/redis-2.2.11/src/redis-cli.c +773 -0
  233. data/redis/redis-2.2.11/src/redis.c +1677 -0
  234. data/redis/redis-2.2.11/src/redis.h +1022 -0
  235. data/redis/redis-2.2.11/src/release.c +13 -0
  236. data/redis/redis-2.2.11/src/replication.c +557 -0
  237. data/redis/redis-2.2.11/src/sds.c +639 -0
  238. data/redis/redis-2.2.11/src/sds.h +78 -0
  239. data/redis/redis-2.2.11/src/sha1.c +276 -0
  240. data/redis/redis-2.2.11/src/sha1.h +17 -0
  241. data/redis/redis-2.2.11/src/solarisfixes.h +22 -0
  242. data/redis/redis-2.2.11/src/sort.c +389 -0
  243. data/redis/redis-2.2.11/src/syncio.c +154 -0
  244. data/redis/redis-2.2.11/src/t_hash.c +476 -0
  245. data/redis/redis-2.2.11/src/t_list.c +986 -0
  246. data/redis/redis-2.2.11/src/t_set.c +610 -0
  247. data/redis/redis-2.2.11/src/t_string.c +438 -0
  248. data/redis/redis-2.2.11/src/t_zset.c +1084 -0
  249. data/redis/redis-2.2.11/src/testhelp.h +54 -0
  250. data/redis/redis-2.2.11/src/util.c +243 -0
  251. data/redis/redis-2.2.11/src/valgrind.sup +5 -0
  252. data/redis/redis-2.2.11/src/version.h +1 -0
  253. data/redis/redis-2.2.11/src/vm.c +1149 -0
  254. data/redis/redis-2.2.11/src/ziplist.c +1323 -0
  255. data/redis/redis-2.2.11/src/ziplist.h +15 -0
  256. data/redis/redis-2.2.11/src/zipmap.c +455 -0
  257. data/redis/redis-2.2.11/src/zipmap.h +48 -0
  258. data/redis/redis-2.2.11/src/zmalloc.c +278 -0
  259. data/redis/redis-2.2.11/src/zmalloc.h +47 -0
  260. data/redis/redis-2.2.11/tests/assets/default.conf +308 -0
  261. data/redis/redis-2.2.11/tests/integration/aof.tcl +104 -0
  262. data/redis/redis-2.2.11/tests/integration/redis-cli.tcl +208 -0
  263. data/redis/redis-2.2.11/tests/integration/replication.tcl +98 -0
  264. data/redis/redis-2.2.11/tests/support/redis.tcl +241 -0
  265. data/redis/redis-2.2.11/tests/support/server.tcl +294 -0
  266. data/redis/redis-2.2.11/tests/support/test.tcl +190 -0
  267. data/redis/redis-2.2.11/tests/support/tmpfile.tcl +15 -0
  268. data/redis/redis-2.2.11/tests/support/util.tcl +296 -0
  269. data/redis/redis-2.2.11/tests/test_helper.tcl +221 -0
  270. data/redis/redis-2.2.11/tests/unit/auth.tcl +15 -0
  271. data/redis/redis-2.2.11/tests/unit/basic.tcl +616 -0
  272. data/redis/redis-2.2.11/tests/unit/cas.tcl +135 -0
  273. data/redis/redis-2.2.11/tests/unit/expire.tcl +74 -0
  274. data/redis/redis-2.2.11/tests/unit/other.tcl +240 -0
  275. data/redis/redis-2.2.11/tests/unit/printver.tcl +6 -0
  276. data/redis/redis-2.2.11/tests/unit/protocol.tcl +62 -0
  277. data/redis/redis-2.2.11/tests/unit/pubsub.tcl +195 -0
  278. data/redis/redis-2.2.11/tests/unit/quit.tcl +40 -0
  279. data/redis/redis-2.2.11/tests/unit/sort.tcl +189 -0
  280. data/redis/redis-2.2.11/tests/unit/type/hash.tcl +300 -0
  281. data/redis/redis-2.2.11/tests/unit/type/list.tcl +819 -0
  282. data/redis/redis-2.2.11/tests/unit/type/set.tcl +334 -0
  283. data/redis/redis-2.2.11/tests/unit/type/zset.tcl +587 -0
  284. data/redis/redis-2.2.11/utils/build-static-symbols.tcl +22 -0
  285. data/redis/redis-2.2.11/utils/generate-command-help.rb +112 -0
  286. data/redis/redis-2.2.11/utils/mktarball.sh +13 -0
  287. data/redis/redis-2.2.11/utils/redis-copy.rb +78 -0
  288. data/redis/redis-2.2.11/utils/redis-sha1.rb +52 -0
  289. data/redis/redis-2.2.11/utils/redis_init_script +42 -0
  290. metadata +362 -0
@@ -0,0 +1,422 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include "intset.h"
5
+ #include "zmalloc.h"
6
+
7
+ /* Note that these encodings are ordered, so:
8
+ * INTSET_ENC_INT16 < INTSET_ENC_INT32 < INTSET_ENC_INT64. */
9
+ #define INTSET_ENC_INT16 (sizeof(int16_t))
10
+ #define INTSET_ENC_INT32 (sizeof(int32_t))
11
+ #define INTSET_ENC_INT64 (sizeof(int64_t))
12
+
13
+ /* Return the required encoding for the provided value. */
14
+ static uint8_t _intsetValueEncoding(int64_t v) {
15
+ if (v < INT32_MIN || v > INT32_MAX)
16
+ return INTSET_ENC_INT64;
17
+ else if (v < INT16_MIN || v > INT16_MAX)
18
+ return INTSET_ENC_INT32;
19
+ return INTSET_ENC_INT16;
20
+ }
21
+
22
+ /* Return the value at pos, given an encoding. */
23
+ static int64_t _intsetGetEncoded(intset *is, int pos, uint8_t enc) {
24
+ if (enc == INTSET_ENC_INT64)
25
+ return ((int64_t*)is->contents)[pos];
26
+ else if (enc == INTSET_ENC_INT32)
27
+ return ((int32_t*)is->contents)[pos];
28
+ return ((int16_t*)is->contents)[pos];
29
+ }
30
+
31
+ /* Return the value at pos, using the configured encoding. */
32
+ static int64_t _intsetGet(intset *is, int pos) {
33
+ return _intsetGetEncoded(is,pos,is->encoding);
34
+ }
35
+
36
+ /* Set the value at pos, using the configured encoding. */
37
+ static void _intsetSet(intset *is, int pos, int64_t value) {
38
+ if (is->encoding == INTSET_ENC_INT64)
39
+ ((int64_t*)is->contents)[pos] = value;
40
+ else if (is->encoding == INTSET_ENC_INT32)
41
+ ((int32_t*)is->contents)[pos] = value;
42
+ else
43
+ ((int16_t*)is->contents)[pos] = value;
44
+ }
45
+
46
+ /* Create an empty intset. */
47
+ intset *intsetNew(void) {
48
+ intset *is = zmalloc(sizeof(intset));
49
+ is->encoding = INTSET_ENC_INT16;
50
+ is->length = 0;
51
+ return is;
52
+ }
53
+
54
+ /* Resize the intset */
55
+ static intset *intsetResize(intset *is, uint32_t len) {
56
+ uint32_t size = len*is->encoding;
57
+ is = zrealloc(is,sizeof(intset)+size);
58
+ return is;
59
+ }
60
+
61
+ /* Search for the position of "value". Return 1 when the value was found and
62
+ * sets "pos" to the position of the value within the intset. Return 0 when
63
+ * the value is not present in the intset and sets "pos" to the position
64
+ * where "value" can be inserted. */
65
+ static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) {
66
+ int min = 0, max = is->length-1, mid = -1;
67
+ int64_t cur = -1;
68
+
69
+ /* The value can never be found when the set is empty */
70
+ if (is->length == 0) {
71
+ if (pos) *pos = 0;
72
+ return 0;
73
+ } else {
74
+ /* Check for the case where we know we cannot find the value,
75
+ * but do know the insert position. */
76
+ if (value > _intsetGet(is,is->length-1)) {
77
+ if (pos) *pos = is->length;
78
+ return 0;
79
+ } else if (value < _intsetGet(is,0)) {
80
+ if (pos) *pos = 0;
81
+ return 0;
82
+ }
83
+ }
84
+
85
+ while(max >= min) {
86
+ mid = (min+max)/2;
87
+ cur = _intsetGet(is,mid);
88
+ if (value > cur) {
89
+ min = mid+1;
90
+ } else if (value < cur) {
91
+ max = mid-1;
92
+ } else {
93
+ break;
94
+ }
95
+ }
96
+
97
+ if (value == cur) {
98
+ if (pos) *pos = mid;
99
+ return 1;
100
+ } else {
101
+ if (pos) *pos = min;
102
+ return 0;
103
+ }
104
+ }
105
+
106
+ /* Upgrades the intset to a larger encoding and inserts the given integer. */
107
+ static intset *intsetUpgradeAndAdd(intset *is, int64_t value) {
108
+ uint8_t curenc = is->encoding;
109
+ uint8_t newenc = _intsetValueEncoding(value);
110
+ int length = is->length;
111
+ int prepend = value < 0 ? 1 : 0;
112
+
113
+ /* First set new encoding and resize */
114
+ is->encoding = newenc;
115
+ is = intsetResize(is,is->length+1);
116
+
117
+ /* Upgrade back-to-front so we don't overwrite values.
118
+ * Note that the "prepend" variable is used to make sure we have an empty
119
+ * space at either the beginning or the end of the intset. */
120
+ while(length--)
121
+ _intsetSet(is,length+prepend,_intsetGetEncoded(is,length,curenc));
122
+
123
+ /* Set the value at the beginning or the end. */
124
+ if (prepend)
125
+ _intsetSet(is,0,value);
126
+ else
127
+ _intsetSet(is,is->length,value);
128
+ is->length++;
129
+ return is;
130
+ }
131
+
132
+ static void intsetMoveTail(intset *is, uint32_t from, uint32_t to) {
133
+ void *src, *dst;
134
+ uint32_t bytes = is->length-from;
135
+ if (is->encoding == INTSET_ENC_INT64) {
136
+ src = (int64_t*)is->contents+from;
137
+ dst = (int64_t*)is->contents+to;
138
+ bytes *= sizeof(int64_t);
139
+ } else if (is->encoding == INTSET_ENC_INT32) {
140
+ src = (int32_t*)is->contents+from;
141
+ dst = (int32_t*)is->contents+to;
142
+ bytes *= sizeof(int32_t);
143
+ } else {
144
+ src = (int16_t*)is->contents+from;
145
+ dst = (int16_t*)is->contents+to;
146
+ bytes *= sizeof(int16_t);
147
+ }
148
+ memmove(dst,src,bytes);
149
+ }
150
+
151
+ /* Insert an integer in the intset */
152
+ intset *intsetAdd(intset *is, int64_t value, uint8_t *success) {
153
+ uint8_t valenc = _intsetValueEncoding(value);
154
+ uint32_t pos;
155
+ if (success) *success = 1;
156
+
157
+ /* Upgrade encoding if necessary. If we need to upgrade, we know that
158
+ * this value should be either appended (if > 0) or prepended (if < 0),
159
+ * because it lies outside the range of existing values. */
160
+ if (valenc > is->encoding) {
161
+ /* This always succeeds, so we don't need to curry *success. */
162
+ return intsetUpgradeAndAdd(is,value);
163
+ } else {
164
+ /* Abort if the value is already present in the set.
165
+ * This call will populate "pos" with the right position to insert
166
+ * the value when it cannot be found. */
167
+ if (intsetSearch(is,value,&pos)) {
168
+ if (success) *success = 0;
169
+ return is;
170
+ }
171
+
172
+ is = intsetResize(is,is->length+1);
173
+ if (pos < is->length) intsetMoveTail(is,pos,pos+1);
174
+ }
175
+
176
+ _intsetSet(is,pos,value);
177
+ is->length++;
178
+ return is;
179
+ }
180
+
181
+ /* Delete integer from intset */
182
+ intset *intsetRemove(intset *is, int64_t value, int *success) {
183
+ uint8_t valenc = _intsetValueEncoding(value);
184
+ uint32_t pos;
185
+ if (success) *success = 0;
186
+
187
+ if (valenc <= is->encoding && intsetSearch(is,value,&pos)) {
188
+ /* We know we can delete */
189
+ if (success) *success = 1;
190
+
191
+ /* Overwrite value with tail and update length */
192
+ if (pos < (is->length-1)) intsetMoveTail(is,pos+1,pos);
193
+ is = intsetResize(is,is->length-1);
194
+ is->length--;
195
+ }
196
+ return is;
197
+ }
198
+
199
+ /* Determine whether a value belongs to this set */
200
+ uint8_t intsetFind(intset *is, int64_t value) {
201
+ uint8_t valenc = _intsetValueEncoding(value);
202
+ return valenc <= is->encoding && intsetSearch(is,value,NULL);
203
+ }
204
+
205
+ /* Return random member */
206
+ int64_t intsetRandom(intset *is) {
207
+ return _intsetGet(is,rand()%is->length);
208
+ }
209
+
210
+ /* Sets the value to the value at the given position. When this position is
211
+ * out of range the function returns 0, when in range it returns 1. */
212
+ uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value) {
213
+ if (pos < is->length) {
214
+ *value = _intsetGet(is,pos);
215
+ return 1;
216
+ }
217
+ return 0;
218
+ }
219
+
220
+ /* Return intset length */
221
+ uint32_t intsetLen(intset *is) {
222
+ return is->length;
223
+ }
224
+
225
+ #ifdef INTSET_TEST_MAIN
226
+ #include <sys/time.h>
227
+
228
+ void intsetRepr(intset *is) {
229
+ int i;
230
+ for (i = 0; i < is->length; i++) {
231
+ printf("%lld\n", (uint64_t)_intsetGet(is,i));
232
+ }
233
+ printf("\n");
234
+ }
235
+
236
+ void error(char *err) {
237
+ printf("%s\n", err);
238
+ exit(1);
239
+ }
240
+
241
+ void ok(void) {
242
+ printf("OK\n");
243
+ }
244
+
245
+ long long usec(void) {
246
+ struct timeval tv;
247
+ gettimeofday(&tv,NULL);
248
+ return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
249
+ }
250
+
251
+ #define assert(_e) ((_e)?(void)0:(_assert(#_e,__FILE__,__LINE__),exit(1)))
252
+ void _assert(char *estr, char *file, int line) {
253
+ printf("\n\n=== ASSERTION FAILED ===\n");
254
+ printf("==> %s:%d '%s' is not true\n",file,line,estr);
255
+ }
256
+
257
+ intset *createSet(int bits, int size) {
258
+ uint64_t mask = (1<<bits)-1;
259
+ uint64_t i, value;
260
+ intset *is = intsetNew();
261
+
262
+ for (i = 0; i < size; i++) {
263
+ if (bits > 32) {
264
+ value = (rand()*rand()) & mask;
265
+ } else {
266
+ value = rand() & mask;
267
+ }
268
+ is = intsetAdd(is,value,NULL);
269
+ }
270
+ return is;
271
+ }
272
+
273
+ void checkConsistency(intset *is) {
274
+ int i;
275
+
276
+ for (i = 0; i < (is->length-1); i++) {
277
+ if (is->encoding == INTSET_ENC_INT16) {
278
+ int16_t *i16 = (int16_t*)is->contents;
279
+ assert(i16[i] < i16[i+1]);
280
+ } else if (is->encoding == INTSET_ENC_INT32) {
281
+ int32_t *i32 = (int32_t*)is->contents;
282
+ assert(i32[i] < i32[i+1]);
283
+ } else {
284
+ int64_t *i64 = (int64_t*)is->contents;
285
+ assert(i64[i] < i64[i+1]);
286
+ }
287
+ }
288
+ }
289
+
290
+ int main(int argc, char **argv) {
291
+ uint8_t success;
292
+ int i;
293
+ intset *is;
294
+ sranddev();
295
+
296
+ printf("Value encodings: "); {
297
+ assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16);
298
+ assert(_intsetValueEncoding(+32767) == INTSET_ENC_INT16);
299
+ assert(_intsetValueEncoding(-32769) == INTSET_ENC_INT32);
300
+ assert(_intsetValueEncoding(+32768) == INTSET_ENC_INT32);
301
+ assert(_intsetValueEncoding(-2147483648) == INTSET_ENC_INT32);
302
+ assert(_intsetValueEncoding(+2147483647) == INTSET_ENC_INT32);
303
+ assert(_intsetValueEncoding(-2147483649) == INTSET_ENC_INT64);
304
+ assert(_intsetValueEncoding(+2147483648) == INTSET_ENC_INT64);
305
+ assert(_intsetValueEncoding(-9223372036854775808ull) == INTSET_ENC_INT64);
306
+ assert(_intsetValueEncoding(+9223372036854775807ull) == INTSET_ENC_INT64);
307
+ ok();
308
+ }
309
+
310
+ printf("Basic adding: "); {
311
+ is = intsetNew();
312
+ is = intsetAdd(is,5,&success); assert(success);
313
+ is = intsetAdd(is,6,&success); assert(success);
314
+ is = intsetAdd(is,4,&success); assert(success);
315
+ is = intsetAdd(is,4,&success); assert(!success);
316
+ ok();
317
+ }
318
+
319
+ printf("Large number of random adds: "); {
320
+ int inserts = 0;
321
+ is = intsetNew();
322
+ for (i = 0; i < 1024; i++) {
323
+ is = intsetAdd(is,rand()%0x800,&success);
324
+ if (success) inserts++;
325
+ }
326
+ assert(is->length == inserts);
327
+ checkConsistency(is);
328
+ ok();
329
+ }
330
+
331
+ printf("Upgrade from int16 to int32: "); {
332
+ is = intsetNew();
333
+ is = intsetAdd(is,32,NULL);
334
+ assert(is->encoding == INTSET_ENC_INT16);
335
+ is = intsetAdd(is,65535,NULL);
336
+ assert(is->encoding == INTSET_ENC_INT32);
337
+ assert(intsetFind(is,32));
338
+ assert(intsetFind(is,65535));
339
+ checkConsistency(is);
340
+
341
+ is = intsetNew();
342
+ is = intsetAdd(is,32,NULL);
343
+ assert(is->encoding == INTSET_ENC_INT16);
344
+ is = intsetAdd(is,-65535,NULL);
345
+ assert(is->encoding == INTSET_ENC_INT32);
346
+ assert(intsetFind(is,32));
347
+ assert(intsetFind(is,-65535));
348
+ checkConsistency(is);
349
+ ok();
350
+ }
351
+
352
+ printf("Upgrade from int16 to int64: "); {
353
+ is = intsetNew();
354
+ is = intsetAdd(is,32,NULL);
355
+ assert(is->encoding == INTSET_ENC_INT16);
356
+ is = intsetAdd(is,4294967295,NULL);
357
+ assert(is->encoding == INTSET_ENC_INT64);
358
+ assert(intsetFind(is,32));
359
+ assert(intsetFind(is,4294967295));
360
+ checkConsistency(is);
361
+
362
+ is = intsetNew();
363
+ is = intsetAdd(is,32,NULL);
364
+ assert(is->encoding == INTSET_ENC_INT16);
365
+ is = intsetAdd(is,-4294967295,NULL);
366
+ assert(is->encoding == INTSET_ENC_INT64);
367
+ assert(intsetFind(is,32));
368
+ assert(intsetFind(is,-4294967295));
369
+ checkConsistency(is);
370
+ ok();
371
+ }
372
+
373
+ printf("Upgrade from int32 to int64: "); {
374
+ is = intsetNew();
375
+ is = intsetAdd(is,65535,NULL);
376
+ assert(is->encoding == INTSET_ENC_INT32);
377
+ is = intsetAdd(is,4294967295,NULL);
378
+ assert(is->encoding == INTSET_ENC_INT64);
379
+ assert(intsetFind(is,65535));
380
+ assert(intsetFind(is,4294967295));
381
+ checkConsistency(is);
382
+
383
+ is = intsetNew();
384
+ is = intsetAdd(is,65535,NULL);
385
+ assert(is->encoding == INTSET_ENC_INT32);
386
+ is = intsetAdd(is,-4294967295,NULL);
387
+ assert(is->encoding == INTSET_ENC_INT64);
388
+ assert(intsetFind(is,65535));
389
+ assert(intsetFind(is,-4294967295));
390
+ checkConsistency(is);
391
+ ok();
392
+ }
393
+
394
+ printf("Stress lookups: "); {
395
+ long num = 100000, size = 10000;
396
+ int i, bits = 20;
397
+ long long start;
398
+ is = createSet(bits,size);
399
+ checkConsistency(is);
400
+
401
+ start = usec();
402
+ for (i = 0; i < num; i++) intsetSearch(is,rand() % ((1<<bits)-1),NULL);
403
+ printf("%ld lookups, %ld element set, %lldusec\n",num,size,usec()-start);
404
+ }
405
+
406
+ printf("Stress add+delete: "); {
407
+ int i, v1, v2;
408
+ is = intsetNew();
409
+ for (i = 0; i < 0xffff; i++) {
410
+ v1 = rand() % 0xfff;
411
+ is = intsetAdd(is,v1,NULL);
412
+ assert(intsetFind(is,v1));
413
+
414
+ v2 = rand() % 0xfff;
415
+ is = intsetRemove(is,v2,NULL);
416
+ assert(!intsetFind(is,v2));
417
+ }
418
+ checkConsistency(is);
419
+ ok();
420
+ }
421
+ }
422
+ #endif
@@ -0,0 +1,19 @@
1
+ #ifndef __INTSET_H
2
+ #define __INTSET_H
3
+ #include <stdint.h>
4
+
5
+ typedef struct intset {
6
+ uint32_t encoding;
7
+ uint32_t length;
8
+ int8_t contents[];
9
+ } intset;
10
+
11
+ intset *intsetNew(void);
12
+ intset *intsetAdd(intset *is, int64_t value, uint8_t *success);
13
+ intset *intsetRemove(intset *is, int64_t value, int *success);
14
+ uint8_t intsetFind(intset *is, int64_t value);
15
+ int64_t intsetRandom(intset *is);
16
+ uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value);
17
+ uint32_t intsetLen(intset *is);
18
+
19
+ #endif // __INTSET_H
@@ -0,0 +1,100 @@
1
+ /*
2
+ * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without modifica-
5
+ * tion, are permitted provided that the following conditions are met:
6
+ *
7
+ * 1. Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ *
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
16
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
18
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
22
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ *
25
+ * Alternatively, the contents of this file may be used under the terms of
26
+ * the GNU General Public License ("GPL") version 2 or any later version,
27
+ * in which case the provisions of the GPL are applicable instead of
28
+ * the above. If you wish to allow the use of your version of this file
29
+ * only under the terms of the GPL and not to allow others to use your
30
+ * version of this file under the BSD license, indicate your decision
31
+ * by deleting the provisions above and replace them with the notice
32
+ * and other provisions required by the GPL. If you do not delete the
33
+ * provisions above, a recipient may use your version of this file under
34
+ * either the BSD or the GPL.
35
+ */
36
+
37
+ #ifndef LZF_H
38
+ #define LZF_H
39
+
40
+ /***********************************************************************
41
+ **
42
+ ** lzf -- an extremely fast/free compression/decompression-method
43
+ ** http://liblzf.plan9.de/
44
+ **
45
+ ** This algorithm is believed to be patent-free.
46
+ **
47
+ ***********************************************************************/
48
+
49
+ #define LZF_VERSION 0x0105 /* 1.5, API version */
50
+
51
+ /*
52
+ * Compress in_len bytes stored at the memory block starting at
53
+ * in_data and write the result to out_data, up to a maximum length
54
+ * of out_len bytes.
55
+ *
56
+ * If the output buffer is not large enough or any error occurs return 0,
57
+ * otherwise return the number of bytes used, which might be considerably
58
+ * more than in_len (but less than 104% of the original size), so it
59
+ * makes sense to always use out_len == in_len - 1), to ensure _some_
60
+ * compression, and store the data uncompressed otherwise (with a flag, of
61
+ * course.
62
+ *
63
+ * lzf_compress might use different algorithms on different systems and
64
+ * even different runs, thus might result in different compressed strings
65
+ * depending on the phase of the moon or similar factors. However, all
66
+ * these strings are architecture-independent and will result in the
67
+ * original data when decompressed using lzf_decompress.
68
+ *
69
+ * The buffers must not be overlapping.
70
+ *
71
+ * If the option LZF_STATE_ARG is enabled, an extra argument must be
72
+ * supplied which is not reflected in this header file. Refer to lzfP.h
73
+ * and lzf_c.c.
74
+ *
75
+ */
76
+ unsigned int
77
+ lzf_compress (const void *const in_data, unsigned int in_len,
78
+ void *out_data, unsigned int out_len);
79
+
80
+ /*
81
+ * Decompress data compressed with some version of the lzf_compress
82
+ * function and stored at location in_data and length in_len. The result
83
+ * will be stored at out_data up to a maximum of out_len characters.
84
+ *
85
+ * If the output buffer is not large enough to hold the decompressed
86
+ * data, a 0 is returned and errno is set to E2BIG. Otherwise the number
87
+ * of decompressed bytes (i.e. the original length of the data) is
88
+ * returned.
89
+ *
90
+ * If an error in the compressed data is detected, a zero is returned and
91
+ * errno is set to EINVAL.
92
+ *
93
+ * This function is very fast, about as fast as a copying loop.
94
+ */
95
+ unsigned int
96
+ lzf_decompress (const void *const in_data, unsigned int in_len,
97
+ void *out_data, unsigned int out_len);
98
+
99
+ #endif
100
+