multi_compress 0.6.0 → 0.7.0

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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -0
  3. data/GET_STARTED.md +5 -3
  4. data/README.md +2 -2
  5. data/THIRD_PARTY_NOTICES.md +3 -3
  6. data/ext/multi_compress/exports.darwin +1 -0
  7. data/ext/multi_compress/exports.map +4 -0
  8. data/ext/multi_compress/extconf.rb +20 -0
  9. data/ext/multi_compress/multi_compress.c +352 -149
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/c/common/version.h +2 -2
  12. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +59 -30
  13. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -3
  14. data/ext/multi_compress/vendor/zstd/lib/BUCK +10 -5
  15. data/ext/multi_compress/vendor/zstd/lib/README.md +25 -5
  16. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +6 -2
  17. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +1 -1
  18. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +3 -3
  19. data/ext/multi_compress/vendor/zstd/lib/common/bmi2.h +40 -0
  20. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +37 -11
  21. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +7 -6
  22. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +4 -3
  23. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +16 -19
  24. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +31 -0
  25. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +16 -2
  26. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +9 -0
  27. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +4 -2
  28. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +300 -3
  29. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +4 -0
  30. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +4 -1
  31. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +775 -214
  32. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +35 -6
  33. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +9 -5
  34. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +14 -5
  35. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +2 -2
  36. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +2 -2
  37. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +49 -5
  38. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +11 -11
  39. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +11 -0
  40. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +16 -18
  41. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +3 -3
  42. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +64 -39
  43. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +30 -2
  44. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +78 -64
  45. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +182 -18
  46. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +59 -27
  47. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +11 -0
  48. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +194 -93
  49. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +225 -85
  50. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +19 -2
  51. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +136 -91
  52. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +77 -77
  53. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +48 -42
  54. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +18 -14
  55. data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +66 -20
  56. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +10 -6
  57. data/ext/multi_compress/vendor/zstd/lib/install_oses.mk +17 -0
  58. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +10 -8
  59. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +5 -364
  60. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +4 -5
  61. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +7 -3
  62. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +8 -5
  63. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +3 -3
  64. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +1 -0
  65. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +8 -7
  66. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +1 -0
  67. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +0 -21
  68. data/ext/multi_compress/vendor/zstd/lib/zstd.h +209 -112
  69. data/lib/multi_compress/active_record.rb +11 -5
  70. data/lib/multi_compress/codec.rb +164 -94
  71. data/lib/multi_compress/database/api.rb +42 -0
  72. data/lib/multi_compress/database/decoding.rb +42 -0
  73. data/lib/multi_compress/database/dictionary.rb +72 -0
  74. data/lib/multi_compress/database/encoding.rb +31 -0
  75. data/lib/multi_compress/database/header.rb +71 -0
  76. data/lib/multi_compress/database/operations.rb +73 -0
  77. data/lib/multi_compress/database/validation.rb +95 -0
  78. data/lib/multi_compress/database.rb +10 -282
  79. data/lib/multi_compress/db_deployment/bundle_archiver.rb +70 -0
  80. data/lib/multi_compress/db_deployment/bundle_metadata.rb +56 -0
  81. data/lib/multi_compress/db_deployment/bundle_stager.rb +62 -0
  82. data/lib/multi_compress/db_deployment/commands.rb +309 -0
  83. data/lib/multi_compress/db_deployment/deployment_bundle.rb +80 -0
  84. data/lib/multi_compress/db_deployment/deterministic_tar_writer.rb +76 -0
  85. data/lib/multi_compress/db_deployment/dictionary_registry.rb +244 -0
  86. data/lib/multi_compress/db_deployment/readable_view.rb +112 -0
  87. data/lib/multi_compress/db_deployment/readable_view_options.rb +51 -0
  88. data/lib/multi_compress/db_deployment/sql_identifiers.rb +45 -0
  89. data/lib/multi_compress/db_deployment.rb +10 -844
  90. data/lib/multi_compress/reader/buffer_operations.rb +57 -0
  91. data/lib/multi_compress/reader/read_operations.rb +69 -0
  92. data/lib/multi_compress/reader.rb +97 -0
  93. data/lib/multi_compress/stream_io.rb +13 -0
  94. data/lib/multi_compress/version.rb +1 -1
  95. data/lib/multi_compress/writer.rb +85 -0
  96. data/lib/multi_compress.rb +42 -333
  97. data/multi_compress.gemspec +2 -0
  98. data/mysql_udf/Makefile +12 -5
  99. data/mysql_udf/multi_compress_mysql.exports +6 -0
  100. data/postgres_extension/Makefile +2 -1
  101. data/postgres_extension/test/run_e2e.sh +28 -10
  102. metadata +30 -10
  103. data/ext/multi_compress/vendor/lz4/lib/Makefile +0 -244
  104. data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +0 -63
  105. data/ext/multi_compress/vendor/zstd/lib/Makefile +0 -389
  106. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +0 -48
@@ -25,23 +25,22 @@
25
25
  */
26
26
 
27
27
  /*- Compiler specifics -*/
28
- #ifdef __clang__
29
- #pragma clang diagnostic ignored "-Wshorten-64-to-32"
30
- #endif
31
-
32
28
  #if defined(_MSC_VER)
33
- # pragma warning(disable : 4244)
34
29
  # pragma warning(disable : 4127) /* C4127 : Condition expression is constant */
35
30
  #endif
36
31
 
37
32
 
38
33
  /*- Dependencies -*/
39
34
  #include <assert.h>
35
+ #include <limits.h>
36
+ #include <stddef.h>
40
37
  #include <stdio.h>
41
38
  #include <stdlib.h>
42
39
 
43
40
  #include "divsufsort.h"
44
41
 
42
+ #define PTRDIFF_TO_INT(x) (assert((x) <= INT_MAX && (x) >= INT_MIN), (int)(x))
43
+
45
44
  /*- Constants -*/
46
45
  #if defined(INLINE)
47
46
  # undef INLINE
@@ -199,8 +198,8 @@ ss_isqrt(int x) {
199
198
  int y, e;
200
199
 
201
200
  if(x >= (SS_BLOCKSIZE * SS_BLOCKSIZE)) { return SS_BLOCKSIZE; }
202
- e = (x & 0xffff0000) ?
203
- ((x & 0xff000000) ?
201
+ e = ((unsigned)x & 0xffff0000) ?
202
+ (((unsigned)x & 0xff000000) ?
204
203
  24 + lg_table[(x >> 24) & 0xff] :
205
204
  16 + lg_table[(x >> 16) & 0xff]) :
206
205
  ((x & 0x0000ff00) ?
@@ -354,7 +353,7 @@ ss_pivot(const unsigned char *Td, const int *PA, int *first, int *last) {
354
353
  int *middle;
355
354
  int t;
356
355
 
357
- t = last - first;
356
+ t = PTRDIFF_TO_INT(last - first);
358
357
  middle = first + t / 2;
359
358
 
360
359
  if(t <= 512) {
@@ -409,7 +408,7 @@ ss_mintrosort(const unsigned char *T, const int *PA,
409
408
  int limit;
410
409
  int v, x = 0;
411
410
 
412
- for(ssize = 0, limit = ss_ilg(last - first);;) {
411
+ for(ssize = 0, limit = ss_ilg(PTRDIFF_TO_INT(last - first));;) {
413
412
 
414
413
  if((last - first) <= SS_INSERTIONSORT_THRESHOLD) {
415
414
  #if 1 < SS_INSERTIONSORT_THRESHOLD
@@ -420,7 +419,7 @@ ss_mintrosort(const unsigned char *T, const int *PA,
420
419
  }
421
420
 
422
421
  Td = T + depth;
423
- if(limit-- == 0) { ss_heapsort(Td, PA, first, last - first); }
422
+ if(limit-- == 0) { ss_heapsort(Td, PA, first, PTRDIFF_TO_INT(last - first)); }
424
423
  if(limit < 0) {
425
424
  for(a = first + 1, v = Td[PA[*first]]; a < last; ++a) {
426
425
  if((x = Td[PA[*a]]) != v) {
@@ -435,16 +434,16 @@ ss_mintrosort(const unsigned char *T, const int *PA,
435
434
  if((a - first) <= (last - a)) {
436
435
  if(1 < (a - first)) {
437
436
  STACK_PUSH(a, last, depth, -1);
438
- last = a, depth += 1, limit = ss_ilg(a - first);
437
+ last = a, depth += 1, limit = ss_ilg(PTRDIFF_TO_INT(a - first));
439
438
  } else {
440
439
  first = a, limit = -1;
441
440
  }
442
441
  } else {
443
442
  if(1 < (last - a)) {
444
- STACK_PUSH(first, a, depth + 1, ss_ilg(a - first));
443
+ STACK_PUSH(first, a, depth + 1, ss_ilg(PTRDIFF_TO_INT(a - first)));
445
444
  first = a, limit = -1;
446
445
  } else {
447
- last = a, depth += 1, limit = ss_ilg(a - first);
446
+ last = a, depth += 1, limit = ss_ilg(PTRDIFF_TO_INT(a - first));
448
447
  }
449
448
  }
450
449
  continue;
@@ -481,9 +480,9 @@ ss_mintrosort(const unsigned char *T, const int *PA,
481
480
  if(a <= d) {
482
481
  c = b - 1;
483
482
 
484
- if((s = a - first) > (t = b - a)) { s = t; }
483
+ if((s = PTRDIFF_TO_INT(a - first)) > (t = PTRDIFF_TO_INT(b - a))) { s = t; }
485
484
  for(e = first, f = b - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }
486
- if((s = d - c) > (t = last - d - 1)) { s = t; }
485
+ if((s = PTRDIFF_TO_INT(d - c)) > (t = PTRDIFF_TO_INT(last - d - 1))) { s = t; }
487
486
  for(e = b, f = last - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }
488
487
 
489
488
  a = first + (b - a), c = last - (d - c);
@@ -491,38 +490,38 @@ ss_mintrosort(const unsigned char *T, const int *PA,
491
490
 
492
491
  if((a - first) <= (last - c)) {
493
492
  if((last - c) <= (c - b)) {
494
- STACK_PUSH(b, c, depth + 1, ss_ilg(c - b));
493
+ STACK_PUSH(b, c, depth + 1, ss_ilg(PTRDIFF_TO_INT(c - b)));
495
494
  STACK_PUSH(c, last, depth, limit);
496
495
  last = a;
497
496
  } else if((a - first) <= (c - b)) {
498
497
  STACK_PUSH(c, last, depth, limit);
499
- STACK_PUSH(b, c, depth + 1, ss_ilg(c - b));
498
+ STACK_PUSH(b, c, depth + 1, ss_ilg(PTRDIFF_TO_INT(c - b)));
500
499
  last = a;
501
500
  } else {
502
501
  STACK_PUSH(c, last, depth, limit);
503
502
  STACK_PUSH(first, a, depth, limit);
504
- first = b, last = c, depth += 1, limit = ss_ilg(c - b);
503
+ first = b, last = c, depth += 1, limit = ss_ilg(PTRDIFF_TO_INT(c - b));
505
504
  }
506
505
  } else {
507
506
  if((a - first) <= (c - b)) {
508
- STACK_PUSH(b, c, depth + 1, ss_ilg(c - b));
507
+ STACK_PUSH(b, c, depth + 1, ss_ilg(PTRDIFF_TO_INT(c - b)));
509
508
  STACK_PUSH(first, a, depth, limit);
510
509
  first = c;
511
510
  } else if((last - c) <= (c - b)) {
512
511
  STACK_PUSH(first, a, depth, limit);
513
- STACK_PUSH(b, c, depth + 1, ss_ilg(c - b));
512
+ STACK_PUSH(b, c, depth + 1, ss_ilg(PTRDIFF_TO_INT(c - b)));
514
513
  first = c;
515
514
  } else {
516
515
  STACK_PUSH(first, a, depth, limit);
517
516
  STACK_PUSH(c, last, depth, limit);
518
- first = b, last = c, depth += 1, limit = ss_ilg(c - b);
517
+ first = b, last = c, depth += 1, limit = ss_ilg(PTRDIFF_TO_INT(c - b));
519
518
  }
520
519
  }
521
520
  } else {
522
521
  limit += 1;
523
522
  if(Td[PA[*first] - 1] < v) {
524
523
  first = ss_partition(PA, first, last, depth);
525
- limit = ss_ilg(last - first);
524
+ limit = ss_ilg(PTRDIFF_TO_INT(last - first));
526
525
  }
527
526
  depth += 1;
528
527
  }
@@ -551,7 +550,8 @@ void
551
550
  ss_rotate(int *first, int *middle, int *last) {
552
551
  int *a, *b, t;
553
552
  int l, r;
554
- l = middle - first, r = last - middle;
553
+ l = PTRDIFF_TO_INT(middle - first);
554
+ r = PTRDIFF_TO_INT(last - middle);
555
555
  for(; (0 < l) && (0 < r);) {
556
556
  if(l == r) { ss_blockswap(first, middle, l); break; }
557
557
  if(l < r) {
@@ -601,7 +601,7 @@ ss_inplacemerge(const unsigned char *T, const int *PA,
601
601
  for(;;) {
602
602
  if(*(last - 1) < 0) { x = 1; p = PA + ~*(last - 1); }
603
603
  else { x = 0; p = PA + *(last - 1); }
604
- for(a = first, len = middle - first, half = len >> 1, r = -1;
604
+ for(a = first, len = PTRDIFF_TO_INT(middle - first), half = len >> 1, r = -1;
605
605
  0 < len;
606
606
  len = half, half >>= 1) {
607
607
  b = a + half;
@@ -640,7 +640,7 @@ ss_mergeforward(const unsigned char *T, const int *PA,
640
640
  int r;
641
641
 
642
642
  bufend = buf + (middle - first) - 1;
643
- ss_blockswap(buf, first, middle - first);
643
+ ss_blockswap(buf, first, PTRDIFF_TO_INT(middle - first));
644
644
 
645
645
  for(t = *(a = first), b = buf, c = middle;;) {
646
646
  r = ss_compare(T, PA + *b, PA + *c, depth);
@@ -692,7 +692,7 @@ ss_mergebackward(const unsigned char *T, const int *PA,
692
692
  int x;
693
693
 
694
694
  bufend = buf + (last - middle) - 1;
695
- ss_blockswap(buf, middle, last - middle);
695
+ ss_blockswap(buf, middle, PTRDIFF_TO_INT(last - middle));
696
696
 
697
697
  x = 0;
698
698
  if(*bufend < 0) { p1 = PA + ~*bufend; x |= 1; }
@@ -781,7 +781,7 @@ ss_swapmerge(const unsigned char *T, const int *PA,
781
781
  continue;
782
782
  }
783
783
 
784
- for(m = 0, len = MIN(middle - first, last - middle), half = len >> 1;
784
+ for(m = 0, len = PTRDIFF_TO_INT(MIN(middle - first, last - middle)), half = len >> 1;
785
785
  0 < len;
786
786
  len = half, half >>= 1) {
787
787
  if(ss_compare(T, PA + GETIDX(*(middle + m + half)),
@@ -850,8 +850,8 @@ sssort(const unsigned char *T, const int *PA,
850
850
  ss_mintrosort(T, PA, first, last, depth);
851
851
  #else
852
852
  if((bufsize < SS_BLOCKSIZE) &&
853
- (bufsize < (last - first)) &&
854
- (bufsize < (limit = ss_isqrt(last - first)))) {
853
+ (bufsize < PTRDIFF_TO_INT(last - first)) &&
854
+ (bufsize < (limit = ss_isqrt(PTRDIFF_TO_INT(last - first))))) {
855
855
  if(SS_BLOCKSIZE < limit) { limit = SS_BLOCKSIZE; }
856
856
  buf = middle = last - limit, bufsize = limit;
857
857
  } else {
@@ -863,7 +863,7 @@ sssort(const unsigned char *T, const int *PA,
863
863
  #elif 1 < SS_BLOCKSIZE
864
864
  ss_insertionsort(T, PA, a, a + SS_BLOCKSIZE, depth);
865
865
  #endif
866
- curbufsize = last - (a + SS_BLOCKSIZE);
866
+ curbufsize = PTRDIFF_TO_INT(last - (a + SS_BLOCKSIZE));
867
867
  curbuf = a + SS_BLOCKSIZE;
868
868
  if(curbufsize <= bufsize) { curbufsize = bufsize, curbuf = buf; }
869
869
  for(b = a, k = SS_BLOCKSIZE, j = i; j & 1; b -= k, k <<= 1, j >>= 1) {
@@ -1016,7 +1016,7 @@ tr_pivot(const int *ISAd, int *first, int *last) {
1016
1016
  int *middle;
1017
1017
  int t;
1018
1018
 
1019
- t = last - first;
1019
+ t = PTRDIFF_TO_INT(last - first);
1020
1020
  middle = first + t / 2;
1021
1021
 
1022
1022
  if(t <= 512) {
@@ -1098,9 +1098,9 @@ tr_partition(const int *ISAd,
1098
1098
 
1099
1099
  if(a <= d) {
1100
1100
  c = b - 1;
1101
- if((s = a - first) > (t = b - a)) { s = t; }
1101
+ if((s = PTRDIFF_TO_INT(a - first)) > (t = PTRDIFF_TO_INT(b - a))) { s = t; }
1102
1102
  for(e = first, f = b - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }
1103
- if((s = d - c) > (t = last - d - 1)) { s = t; }
1103
+ if((s = PTRDIFF_TO_INT(d - c)) > (t = PTRDIFF_TO_INT(last - d - 1))) { s = t; }
1104
1104
  for(e = b, f = last - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }
1105
1105
  first += (b - a), last -= (d - c);
1106
1106
  }
@@ -1117,17 +1117,17 @@ tr_copy(int *ISA, const int *SA,
1117
1117
  int *c, *d, *e;
1118
1118
  int s, v;
1119
1119
 
1120
- v = b - SA - 1;
1120
+ v = PTRDIFF_TO_INT(b - SA - 1);
1121
1121
  for(c = first, d = a - 1; c <= d; ++c) {
1122
1122
  if((0 <= (s = *c - depth)) && (ISA[s] == v)) {
1123
1123
  *++d = s;
1124
- ISA[s] = d - SA;
1124
+ ISA[s] = PTRDIFF_TO_INT(d - SA);
1125
1125
  }
1126
1126
  }
1127
1127
  for(c = last - 1, e = d + 1, d = b; e < d; --c) {
1128
1128
  if((0 <= (s = *c - depth)) && (ISA[s] == v)) {
1129
1129
  *--d = s;
1130
- ISA[s] = d - SA;
1130
+ ISA[s] = PTRDIFF_TO_INT(d - SA);
1131
1131
  }
1132
1132
  }
1133
1133
  }
@@ -1141,13 +1141,13 @@ tr_partialcopy(int *ISA, const int *SA,
1141
1141
  int s, v;
1142
1142
  int rank, lastrank, newrank = -1;
1143
1143
 
1144
- v = b - SA - 1;
1144
+ v = PTRDIFF_TO_INT(b - SA - 1);
1145
1145
  lastrank = -1;
1146
1146
  for(c = first, d = a - 1; c <= d; ++c) {
1147
1147
  if((0 <= (s = *c - depth)) && (ISA[s] == v)) {
1148
1148
  *++d = s;
1149
1149
  rank = ISA[s + depth];
1150
- if(lastrank != rank) { lastrank = rank; newrank = d - SA; }
1150
+ if(lastrank != rank) { lastrank = rank; newrank = PTRDIFF_TO_INT(d - SA); }
1151
1151
  ISA[s] = newrank;
1152
1152
  }
1153
1153
  }
@@ -1155,7 +1155,7 @@ tr_partialcopy(int *ISA, const int *SA,
1155
1155
  lastrank = -1;
1156
1156
  for(e = d; first <= e; --e) {
1157
1157
  rank = ISA[*e];
1158
- if(lastrank != rank) { lastrank = rank; newrank = e - SA; }
1158
+ if(lastrank != rank) { lastrank = rank; newrank = PTRDIFF_TO_INT(e - SA); }
1159
1159
  if(newrank != rank) { ISA[*e] = newrank; }
1160
1160
  }
1161
1161
 
@@ -1164,7 +1164,7 @@ tr_partialcopy(int *ISA, const int *SA,
1164
1164
  if((0 <= (s = *c - depth)) && (ISA[s] == v)) {
1165
1165
  *--d = s;
1166
1166
  rank = ISA[s + depth];
1167
- if(lastrank != rank) { lastrank = rank; newrank = d - SA; }
1167
+ if(lastrank != rank) { lastrank = rank; newrank = PTRDIFF_TO_INT(d - SA); }
1168
1168
  ISA[s] = newrank;
1169
1169
  }
1170
1170
  }
@@ -1180,23 +1180,23 @@ tr_introsort(int *ISA, const int *ISAd,
1180
1180
  int *a, *b, *c;
1181
1181
  int t;
1182
1182
  int v, x = 0;
1183
- int incr = ISAd - ISA;
1183
+ int incr = PTRDIFF_TO_INT(ISAd - ISA);
1184
1184
  int limit, next;
1185
1185
  int ssize, trlink = -1;
1186
1186
 
1187
- for(ssize = 0, limit = tr_ilg(last - first);;) {
1187
+ for(ssize = 0, limit = tr_ilg(PTRDIFF_TO_INT(last - first));;) {
1188
1188
 
1189
1189
  if(limit < 0) {
1190
1190
  if(limit == -1) {
1191
1191
  /* tandem repeat partition */
1192
- tr_partition(ISAd - incr, first, first, last, &a, &b, last - SA - 1);
1192
+ tr_partition(ISAd - incr, first, first, last, &a, &b, PTRDIFF_TO_INT(last - SA - 1));
1193
1193
 
1194
1194
  /* update ranks */
1195
1195
  if(a < last) {
1196
- for(c = first, v = a - SA - 1; c < a; ++c) { ISA[*c] = v; }
1196
+ for(c = first, v = PTRDIFF_TO_INT(a - SA - 1); c < a; ++c) { ISA[*c] = v; }
1197
1197
  }
1198
1198
  if(b < last) {
1199
- for(c = a, v = b - SA - 1; c < b; ++c) { ISA[*c] = v; }
1199
+ for(c = a, v = PTRDIFF_TO_INT(b - SA - 1); c < b; ++c) { ISA[*c] = v; }
1200
1200
  }
1201
1201
 
1202
1202
  /* push */
@@ -1207,19 +1207,19 @@ tr_introsort(int *ISA, const int *ISAd,
1207
1207
  }
1208
1208
  if((a - first) <= (last - b)) {
1209
1209
  if(1 < (a - first)) {
1210
- STACK_PUSH5(ISAd, b, last, tr_ilg(last - b), trlink);
1211
- last = a, limit = tr_ilg(a - first);
1210
+ STACK_PUSH5(ISAd, b, last, tr_ilg(PTRDIFF_TO_INT(last - b)), trlink);
1211
+ last = a, limit = tr_ilg(PTRDIFF_TO_INT(a - first));
1212
1212
  } else if(1 < (last - b)) {
1213
- first = b, limit = tr_ilg(last - b);
1213
+ first = b, limit = tr_ilg(PTRDIFF_TO_INT(last - b));
1214
1214
  } else {
1215
1215
  STACK_POP5(ISAd, first, last, limit, trlink);
1216
1216
  }
1217
1217
  } else {
1218
1218
  if(1 < (last - b)) {
1219
- STACK_PUSH5(ISAd, first, a, tr_ilg(a - first), trlink);
1220
- first = b, limit = tr_ilg(last - b);
1219
+ STACK_PUSH5(ISAd, first, a, tr_ilg(PTRDIFF_TO_INT(a - first)), trlink);
1220
+ first = b, limit = tr_ilg(PTRDIFF_TO_INT(last - b));
1221
1221
  } else if(1 < (a - first)) {
1222
- last = a, limit = tr_ilg(a - first);
1222
+ last = a, limit = tr_ilg(PTRDIFF_TO_INT(a - first));
1223
1223
  } else {
1224
1224
  STACK_POP5(ISAd, first, last, limit, trlink);
1225
1225
  }
@@ -1228,26 +1228,26 @@ tr_introsort(int *ISA, const int *ISAd,
1228
1228
  /* tandem repeat copy */
1229
1229
  a = stack[--ssize].b, b = stack[ssize].c;
1230
1230
  if(stack[ssize].d == 0) {
1231
- tr_copy(ISA, SA, first, a, b, last, ISAd - ISA);
1231
+ tr_copy(ISA, SA, first, a, b, last, PTRDIFF_TO_INT(ISAd - ISA));
1232
1232
  } else {
1233
1233
  if(0 <= trlink) { stack[trlink].d = -1; }
1234
- tr_partialcopy(ISA, SA, first, a, b, last, ISAd - ISA);
1234
+ tr_partialcopy(ISA, SA, first, a, b, last, PTRDIFF_TO_INT(ISAd - ISA));
1235
1235
  }
1236
1236
  STACK_POP5(ISAd, first, last, limit, trlink);
1237
1237
  } else {
1238
1238
  /* sorted partition */
1239
1239
  if(0 <= *first) {
1240
1240
  a = first;
1241
- do { ISA[*a] = a - SA; } while((++a < last) && (0 <= *a));
1241
+ do { ISA[*a] = PTRDIFF_TO_INT(a - SA); } while((++a < last) && (0 <= *a));
1242
1242
  first = a;
1243
1243
  }
1244
1244
  if(first < last) {
1245
1245
  a = first; do { *a = ~*a; } while(*++a < 0);
1246
- next = (ISA[*a] != ISAd[*a]) ? tr_ilg(a - first + 1) : -1;
1247
- if(++a < last) { for(b = first, v = a - SA - 1; b < a; ++b) { ISA[*b] = v; } }
1246
+ next = (ISA[*a] != ISAd[*a]) ? tr_ilg(PTRDIFF_TO_INT(a - first + 1)) : -1;
1247
+ if(++a < last) { for(b = first, v = PTRDIFF_TO_INT(a - SA - 1); b < a; ++b) { ISA[*b] = v; } }
1248
1248
 
1249
1249
  /* push */
1250
- if(trbudget_check(budget, a - first)) {
1250
+ if(trbudget_check(budget, PTRDIFF_TO_INT(a - first))) {
1251
1251
  if((a - first) <= (last - a)) {
1252
1252
  STACK_PUSH5(ISAd, a, last, -3, trlink);
1253
1253
  ISAd += incr, last = a, limit = next;
@@ -1281,7 +1281,7 @@ tr_introsort(int *ISA, const int *ISAd,
1281
1281
  }
1282
1282
 
1283
1283
  if(limit-- == 0) {
1284
- tr_heapsort(ISAd, first, last - first);
1284
+ tr_heapsort(ISAd, first, PTRDIFF_TO_INT(last - first));
1285
1285
  for(a = last - 1; first < a; a = b) {
1286
1286
  for(x = ISAd[*a], b = a - 1; (first <= b) && (ISAd[*b] == x); --b) { *b = ~*b; }
1287
1287
  }
@@ -1297,14 +1297,14 @@ tr_introsort(int *ISA, const int *ISAd,
1297
1297
  /* partition */
1298
1298
  tr_partition(ISAd, first, first + 1, last, &a, &b, v);
1299
1299
  if((last - first) != (b - a)) {
1300
- next = (ISA[*a] != v) ? tr_ilg(b - a) : -1;
1300
+ next = (ISA[*a] != v) ? tr_ilg(PTRDIFF_TO_INT(b - a)) : -1;
1301
1301
 
1302
1302
  /* update ranks */
1303
- for(c = first, v = a - SA - 1; c < a; ++c) { ISA[*c] = v; }
1304
- if(b < last) { for(c = a, v = b - SA - 1; c < b; ++c) { ISA[*c] = v; } }
1303
+ for(c = first, v = PTRDIFF_TO_INT(a - SA - 1); c < a; ++c) { ISA[*c] = v; }
1304
+ if(b < last) { for(c = a, v = PTRDIFF_TO_INT(b - SA - 1); c < b; ++c) { ISA[*c] = v; } }
1305
1305
 
1306
1306
  /* push */
1307
- if((1 < (b - a)) && (trbudget_check(budget, b - a))) {
1307
+ if((1 < (b - a)) && (trbudget_check(budget, PTRDIFF_TO_INT(b - a)))) {
1308
1308
  if((a - first) <= (last - b)) {
1309
1309
  if((last - b) <= (b - a)) {
1310
1310
  if(1 < (a - first)) {
@@ -1381,8 +1381,8 @@ tr_introsort(int *ISA, const int *ISAd,
1381
1381
  }
1382
1382
  }
1383
1383
  } else {
1384
- if(trbudget_check(budget, last - first)) {
1385
- limit = tr_ilg(last - first), ISAd += incr;
1384
+ if(trbudget_check(budget, PTRDIFF_TO_INT(last - first))) {
1385
+ limit = tr_ilg(PTRDIFF_TO_INT(last - first)), ISAd += incr;
1386
1386
  } else {
1387
1387
  if(0 <= trlink) { stack[trlink].d = -1; }
1388
1388
  STACK_POP5(ISAd, first, last, limit, trlink);
@@ -1420,7 +1420,7 @@ trsort(int *ISA, int *SA, int n, int depth) {
1420
1420
  budget.count = 0;
1421
1421
  tr_introsort(ISA, ISAd, SA, first, last, &budget);
1422
1422
  if(budget.count != 0) { unsorted += budget.count; }
1423
- else { skip = first - last; }
1423
+ else { skip = PTRDIFF_TO_INT(first - last); }
1424
1424
  } else if((last - first) == 1) {
1425
1425
  skip = -1;
1426
1426
  }
@@ -1634,7 +1634,7 @@ construct_SA(const unsigned char *T, int *SA,
1634
1634
  c0 = T[--s];
1635
1635
  if((0 < s) && (T[s - 1] > c0)) { s = ~s; }
1636
1636
  if(c0 != c2) {
1637
- if(0 <= c2) { BUCKET_B(c2, c1) = k - SA; }
1637
+ if(0 <= c2) { BUCKET_B(c2, c1) = PTRDIFF_TO_INT(k - SA); }
1638
1638
  k = SA + BUCKET_B(c2 = c0, c1);
1639
1639
  }
1640
1640
  assert(k < j); assert(k != NULL);
@@ -1658,7 +1658,7 @@ construct_SA(const unsigned char *T, int *SA,
1658
1658
  c0 = T[--s];
1659
1659
  if((s == 0) || (T[s - 1] < c0)) { s = ~s; }
1660
1660
  if(c0 != c2) {
1661
- BUCKET_A(c2) = k - SA;
1661
+ BUCKET_A(c2) = PTRDIFF_TO_INT(k - SA);
1662
1662
  k = SA + BUCKET_A(c2 = c0);
1663
1663
  }
1664
1664
  assert(i < k);
@@ -1698,7 +1698,7 @@ construct_BWT(const unsigned char *T, int *SA,
1698
1698
  *j = ~((int)c0);
1699
1699
  if((0 < s) && (T[s - 1] > c0)) { s = ~s; }
1700
1700
  if(c0 != c2) {
1701
- if(0 <= c2) { BUCKET_B(c2, c1) = k - SA; }
1701
+ if(0 <= c2) { BUCKET_B(c2, c1) = PTRDIFF_TO_INT(k - SA); }
1702
1702
  k = SA + BUCKET_B(c2 = c0, c1);
1703
1703
  }
1704
1704
  assert(k < j); assert(k != NULL);
@@ -1726,7 +1726,7 @@ construct_BWT(const unsigned char *T, int *SA,
1726
1726
  *i = c0;
1727
1727
  if((0 < s) && (T[s - 1] < c0)) { s = ~((int)T[s - 1]); }
1728
1728
  if(c0 != c2) {
1729
- BUCKET_A(c2) = k - SA;
1729
+ BUCKET_A(c2) = PTRDIFF_TO_INT(k - SA);
1730
1730
  k = SA + BUCKET_A(c2 = c0);
1731
1731
  }
1732
1732
  assert(i < k);
@@ -1738,7 +1738,7 @@ construct_BWT(const unsigned char *T, int *SA,
1738
1738
  }
1739
1739
  }
1740
1740
 
1741
- return orig - SA;
1741
+ return PTRDIFF_TO_INT(orig - SA);
1742
1742
  }
1743
1743
 
1744
1744
  /* Constructs the burrows-wheeler transformed string directly
@@ -1776,13 +1776,13 @@ construct_BWT_indexes(const unsigned char *T, int *SA,
1776
1776
  assert(((s + 1) < n) && (T[s] <= T[s + 1]));
1777
1777
  assert(T[s - 1] <= T[s]);
1778
1778
 
1779
- if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = j - SA;
1779
+ if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = PTRDIFF_TO_INT(j - SA);
1780
1780
 
1781
1781
  c0 = T[--s];
1782
1782
  *j = ~((int)c0);
1783
1783
  if((0 < s) && (T[s - 1] > c0)) { s = ~s; }
1784
1784
  if(c0 != c2) {
1785
- if(0 <= c2) { BUCKET_B(c2, c1) = k - SA; }
1785
+ if(0 <= c2) { BUCKET_B(c2, c1) = PTRDIFF_TO_INT(k - SA); }
1786
1786
  k = SA + BUCKET_B(c2 = c0, c1);
1787
1787
  }
1788
1788
  assert(k < j); assert(k != NULL);
@@ -1802,7 +1802,7 @@ construct_BWT_indexes(const unsigned char *T, int *SA,
1802
1802
  the sorted order of type B suffixes. */
1803
1803
  k = SA + BUCKET_A(c2 = T[n - 1]);
1804
1804
  if (T[n - 2] < c2) {
1805
- if (((n - 1) & mod) == 0) indexes[(n - 1) / (mod + 1) - 1] = k - SA;
1805
+ if (((n - 1) & mod) == 0) indexes[(n - 1) / (mod + 1) - 1] = PTRDIFF_TO_INT(k - SA);
1806
1806
  *k++ = ~((int)T[n - 2]);
1807
1807
  }
1808
1808
  else {
@@ -1814,17 +1814,17 @@ construct_BWT_indexes(const unsigned char *T, int *SA,
1814
1814
  if(0 < (s = *i)) {
1815
1815
  assert(T[s - 1] >= T[s]);
1816
1816
 
1817
- if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = i - SA;
1817
+ if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = PTRDIFF_TO_INT(i - SA);
1818
1818
 
1819
1819
  c0 = T[--s];
1820
1820
  *i = c0;
1821
1821
  if(c0 != c2) {
1822
- BUCKET_A(c2) = k - SA;
1822
+ BUCKET_A(c2) = PTRDIFF_TO_INT(k - SA);
1823
1823
  k = SA + BUCKET_A(c2 = c0);
1824
1824
  }
1825
1825
  assert(i < k);
1826
1826
  if((0 < s) && (T[s - 1] < c0)) {
1827
- if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = k - SA;
1827
+ if ((s & mod) == 0) indexes[s / (mod + 1) - 1] = PTRDIFF_TO_INT(k - SA);
1828
1828
  *k++ = ~((int)T[s - 1]);
1829
1829
  } else
1830
1830
  *k++ = s;
@@ -1835,7 +1835,7 @@ construct_BWT_indexes(const unsigned char *T, int *SA,
1835
1835
  }
1836
1836
  }
1837
1837
 
1838
- return orig - SA;
1838
+ return PTRDIFF_TO_INT(orig - SA);
1839
1839
  }
1840
1840
 
1841
1841