@@ -1108,22 +1108,39 @@ function loadDatabase(hooks) {
1108
1108
const id2 = id1 + ( ( nodeid [ 4 ] << 8 ) | nodeid [ 5 ] ) ;
1109
1109
leaves = RoaringBitmap . makeSingleton ( id1 )
1110
1110
. union ( RoaringBitmap . makeSingleton ( id2 ) ) ;
1111
+ } else if ( ! isWhole && ( nodeid [ 0 ] & 0xf0 ) === 0x80 ) {
1112
+ const id1 = ( ( nodeid [ 0 ] & 0x0f ) << 16 ) | ( nodeid [ 1 ] << 8 ) | nodeid [ 2 ] ;
1113
+ const id2 = id1 + ( ( nodeid [ 3 ] << 4 ) | ( ( nodeid [ 4 ] >> 4 ) & 0x0f ) ) ;
1114
+ const id3 = id2 + ( ( ( nodeid [ 4 ] & 0x0f ) << 8 ) | nodeid [ 5 ] ) ;
1115
+ leaves = RoaringBitmap . makeSingleton ( id1 )
1116
+ . union ( RoaringBitmap . makeSingleton ( id2 ) )
1117
+ . union ( RoaringBitmap . makeSingleton ( id3 ) ) ;
1111
1118
} else {
1112
1119
leaves = RoaringBitmap . makeSingleton (
1113
1120
( nodeid [ 2 ] << 24 ) | ( nodeid [ 3 ] << 16 ) |
1114
1121
( nodeid [ 4 ] << 8 ) | nodeid [ 5 ] ,
1115
1122
) ;
1116
1123
}
1117
- const data = ( nodeid [ 0 ] & 0x20 ) !== 0 ?
1118
- Uint8Array . of ( ( ( nodeid [ 0 ] & 0x0f ) << 4 ) | ( nodeid [ 1 ] >> 4 ) ) :
1119
- EMPTY_UINT8 ;
1120
- newPromise = Promise . resolve ( new PrefixSearchTree (
1121
- EMPTY_SEARCH_TREE_BRANCHES ,
1122
- EMPTY_SEARCH_TREE_BRANCHES ,
1123
- data ,
1124
- isWhole ? leaves : EMPTY_BITMAP ,
1125
- isWhole ? EMPTY_BITMAP : leaves ,
1126
- ) ) ;
1124
+ if ( isWhole ) {
1125
+ const data = ( nodeid [ 0 ] & 0x20 ) !== 0 ?
1126
+ Uint8Array . of ( ( ( nodeid [ 0 ] & 0x0f ) << 4 ) | ( nodeid [ 1 ] >> 4 ) ) :
1127
+ EMPTY_UINT8 ;
1128
+ newPromise = Promise . resolve ( new PrefixSearchTree (
1129
+ EMPTY_SEARCH_TREE_BRANCHES ,
1130
+ EMPTY_SEARCH_TREE_BRANCHES ,
1131
+ data ,
1132
+ leaves ,
1133
+ EMPTY_BITMAP ,
1134
+ ) ) ;
1135
+ } else {
1136
+ const data = ( nodeid [ 0 ] & 0xf0 ) === 0x80 ? 0 : (
1137
+ ( ( nodeid [ 0 ] & 0x0f ) << 4 ) | ( nodeid [ 1 ] >> 4 ) ) ;
1138
+ newPromise = Promise . resolve ( new SuffixSearchTree (
1139
+ EMPTY_SEARCH_TREE_BRANCHES ,
1140
+ data ,
1141
+ leaves ,
1142
+ ) ) ;
1143
+ }
1127
1144
} else {
1128
1145
const hashHex = makeHexFromUint8Array ( nodeid ) ;
1129
1146
newPromise = new Promise ( ( resolve , reject ) => {
@@ -2748,6 +2765,7 @@ function loadDatabase(hooks) {
2748
2765
// because that's the canonical, hashed version of the data
2749
2766
let compression_tag = input [ i ] ;
2750
2767
const is_pure_suffixes_only_node = ( compression_tag & 0x01 ) !== 0 ;
2768
+ let no_leaves_flag ;
2751
2769
if ( compression_tag > 1 ) {
2752
2770
// compressed node
2753
2771
const is_long_compressed = ( compression_tag & 0x04 ) !== 0 ;
@@ -2759,7 +2777,8 @@ function loadDatabase(hooks) {
2759
2777
compression_tag |= input [ i ] << 16 ;
2760
2778
i += 1 ;
2761
2779
}
2762
- let dlen = input [ i ] ;
2780
+ let dlen = input [ i ] & 0x7F ;
2781
+ no_leaves_flag = input [ i ] & 0x80 ;
2763
2782
i += 1 ;
2764
2783
if ( is_data_compressed ) {
2765
2784
data = data_history [ data_history . length - dlen - 1 ] ;
@@ -2786,10 +2805,15 @@ function loadDatabase(hooks) {
2786
2805
let whole ;
2787
2806
let suffix ;
2788
2807
if ( is_pure_suffixes_only_node ) {
2789
- suffix = input [ i ] === 0 ?
2790
- EMPTY_BITMAP1 :
2791
- new RoaringBitmap ( input , i ) ;
2792
- i += suffix . consumed_len_bytes ;
2808
+ if ( no_leaves_flag ) {
2809
+ whole = EMPTY_BITMAP ;
2810
+ suffix = EMPTY_BITMAP ;
2811
+ } else {
2812
+ suffix = input [ i ] === 0 ?
2813
+ EMPTY_BITMAP1 :
2814
+ new RoaringBitmap ( input , i ) ;
2815
+ i += suffix . consumed_len_bytes ;
2816
+ }
2793
2817
tree = new SuffixSearchTree (
2794
2818
branches ,
2795
2819
dlen ,
@@ -2807,7 +2831,7 @@ function loadDatabase(hooks) {
2807
2831
let ci = 0 ;
2808
2832
canonical [ ci ] = 1 ;
2809
2833
ci += 1 ;
2810
- canonical [ ci ] = dlen ;
2834
+ canonical [ ci ] = dlen | no_leaves_flag ;
2811
2835
ci += 1 ;
2812
2836
canonical [ ci ] = input [ coffset ] ; // suffix child count
2813
2837
ci += 1 ;
@@ -2821,10 +2845,9 @@ function loadDatabase(hooks) {
2821
2845
}
2822
2846
siphashOfBytes ( canonical . subarray ( 0 , clen ) , 0 , 0 , 0 , 0 , hash ) ;
2823
2847
} else {
2824
- if ( input [ i ] === 0xff ) {
2848
+ if ( no_leaves_flag ) {
2825
2849
whole = EMPTY_BITMAP ;
2826
- suffix = EMPTY_BITMAP1 ;
2827
- i += 1 ;
2850
+ suffix = EMPTY_BITMAP ;
2828
2851
} else {
2829
2852
whole = input [ i ] === 0 ?
2830
2853
EMPTY_BITMAP1 :
@@ -2856,7 +2879,7 @@ function loadDatabase(hooks) {
2856
2879
let ci = 0 ;
2857
2880
canonical [ ci ] = 0 ;
2858
2881
ci += 1 ;
2859
- canonical [ ci ] = dlen ;
2882
+ canonical [ ci ] = dlen | no_leaves_flag ;
2860
2883
ci += 1 ;
2861
2884
canonical . set ( data , ci ) ;
2862
2885
ci += data . length ;
@@ -2880,9 +2903,11 @@ function loadDatabase(hooks) {
2880
2903
}
2881
2904
hash [ 2 ] &= 0x7f ;
2882
2905
} else {
2906
+ i += 1 ;
2883
2907
// uncompressed node
2884
- const dlen = input [ i + 1 ] ;
2885
- i += 2 ;
2908
+ const dlen = input [ i ] & 0x7F ;
2909
+ no_leaves_flag = input [ i ] & 0x80 ;
2910
+ i += 1 ;
2886
2911
if ( dlen === 0 || is_pure_suffixes_only_node ) {
2887
2912
data = EMPTY_UINT8 ;
2888
2913
} else {
@@ -2897,16 +2922,15 @@ function loadDatabase(hooks) {
2897
2922
i += branches_consumed_len_bytes ;
2898
2923
let whole ;
2899
2924
let suffix ;
2900
- if ( is_pure_suffixes_only_node ) {
2925
+ if ( no_leaves_flag ) {
2926
+ whole = EMPTY_BITMAP ;
2927
+ suffix = EMPTY_BITMAP ;
2928
+ } else if ( is_pure_suffixes_only_node ) {
2901
2929
whole = EMPTY_BITMAP ;
2902
2930
suffix = input [ i ] === 0 ?
2903
2931
EMPTY_BITMAP1 :
2904
2932
new RoaringBitmap ( input , i ) ;
2905
2933
i += suffix . consumed_len_bytes ;
2906
- } else if ( input [ i ] === 0xff ) {
2907
- whole = EMPTY_BITMAP ;
2908
- suffix = EMPTY_BITMAP ;
2909
- i += 1 ;
2910
2934
} else {
2911
2935
whole = input [ i ] === 0 ?
2912
2936
EMPTY_BITMAP1 :
0 commit comments