36
36
37
37
static nghttp3_ksl_blk null_blk = {{{NULL , NULL , 0 , 0 , {0 }}}};
38
38
39
- nghttp3_objalloc_def (ksl_blk , nghttp3_ksl_blk , oplent );
39
+ nghttp3_objalloc_def (ksl_blk , nghttp3_ksl_blk , oplent )
40
40
41
41
static size_t ksl_nodelen (size_t keylen ) {
42
42
assert (keylen >= sizeof (uint64_t ));
@@ -59,7 +59,8 @@ static void ksl_node_set_key(nghttp3_ksl *ksl, nghttp3_ksl_node *node,
59
59
}
60
60
61
61
void nghttp3_ksl_init (nghttp3_ksl * ksl , nghttp3_ksl_compar compar ,
62
- size_t keylen , const nghttp3_mem * mem ) {
62
+ nghttp3_ksl_search search , size_t keylen ,
63
+ const nghttp3_mem * mem ) {
63
64
size_t nodelen = ksl_nodelen (keylen );
64
65
65
66
nghttp3_objalloc_init (& ksl -> blkalloc ,
@@ -68,6 +69,7 @@ void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
68
69
ksl -> head = NULL ;
69
70
ksl -> front = ksl -> back = NULL ;
70
71
ksl -> compar = compar ;
72
+ ksl -> search = search ;
71
73
ksl -> n = 0 ;
72
74
ksl -> keylen = keylen ;
73
75
ksl -> nodelen = nodelen ;
@@ -274,20 +276,6 @@ static void ksl_insert_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i,
274
276
++ blk -> n ;
275
277
}
276
278
277
- static size_t ksl_search (const nghttp3_ksl * ksl , nghttp3_ksl_blk * blk ,
278
- const nghttp3_ksl_key * key ,
279
- nghttp3_ksl_compar compar ) {
280
- size_t i ;
281
- nghttp3_ksl_node * node ;
282
-
283
- for (i = 0 , node = (nghttp3_ksl_node * )(void * )blk -> nodes ;
284
- i < blk -> n && compar ((nghttp3_ksl_key * )node -> key , key );
285
- ++ i , node = (nghttp3_ksl_node * )(void * )((uint8_t * )node + ksl -> nodelen ))
286
- ;
287
-
288
- return i ;
289
- }
290
-
291
279
int nghttp3_ksl_insert (nghttp3_ksl * ksl , nghttp3_ksl_it * it ,
292
280
const nghttp3_ksl_key * key , void * data ) {
293
281
nghttp3_ksl_blk * blk ;
@@ -312,7 +300,7 @@ int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
312
300
blk = ksl -> head ;
313
301
314
302
for (;;) {
315
- i = ksl_search (ksl , blk , key , ksl -> compar );
303
+ i = ksl -> search (ksl , blk , key );
316
304
317
305
if (blk -> leaf ) {
318
306
if (i < blk -> n &&
@@ -571,7 +559,7 @@ int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
571
559
}
572
560
573
561
for (;;) {
574
- i = ksl_search (ksl , blk , key , ksl -> compar );
562
+ i = ksl -> search (ksl , blk , key );
575
563
576
564
if (i == blk -> n ) {
577
565
if (it ) {
@@ -642,12 +630,12 @@ int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
642
630
643
631
nghttp3_ksl_it nghttp3_ksl_lower_bound (const nghttp3_ksl * ksl ,
644
632
const nghttp3_ksl_key * key ) {
645
- return nghttp3_ksl_lower_bound_compar (ksl , key , ksl -> compar );
633
+ return nghttp3_ksl_lower_bound_search (ksl , key , ksl -> search );
646
634
}
647
635
648
- nghttp3_ksl_it nghttp3_ksl_lower_bound_compar (const nghttp3_ksl * ksl ,
636
+ nghttp3_ksl_it nghttp3_ksl_lower_bound_search (const nghttp3_ksl * ksl ,
649
637
const nghttp3_ksl_key * key ,
650
- nghttp3_ksl_compar compar ) {
638
+ nghttp3_ksl_search search ) {
651
639
nghttp3_ksl_blk * blk = ksl -> head ;
652
640
nghttp3_ksl_it it ;
653
641
size_t i ;
@@ -658,7 +646,7 @@ nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(const nghttp3_ksl *ksl,
658
646
}
659
647
660
648
for (;;) {
661
- i = ksl_search (ksl , blk , key , compar );
649
+ i = search (ksl , blk , key );
662
650
663
651
if (blk -> leaf ) {
664
652
if (i == blk -> n && blk -> next ) {
@@ -702,7 +690,7 @@ void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key,
702
690
assert (ksl -> head );
703
691
704
692
for (;;) {
705
- i = ksl_search (ksl , blk , old_key , ksl -> compar );
693
+ i = ksl -> search (ksl , blk , old_key );
706
694
707
695
assert (i < blk -> n );
708
696
node = nghttp3_ksl_nth_node (ksl , blk , i );
@@ -825,9 +813,50 @@ int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
825
813
return a -> begin < b -> begin ;
826
814
}
827
815
816
+ nghttp3_ksl_search_def (range , nghttp3_ksl_range_compar )
817
+
818
+ size_t nghttp3_ksl_range_search (const nghttp3_ksl * ksl , nghttp3_ksl_blk * blk ,
819
+ const nghttp3_ksl_key * key ) {
820
+ return ksl_range_search (ksl , blk , key );
821
+ }
822
+
828
823
int nghttp3_ksl_range_exclusive_compar (const nghttp3_ksl_key * lhs ,
829
824
const nghttp3_ksl_key * rhs ) {
830
825
const nghttp3_range * a = lhs , * b = rhs ;
831
826
return a -> begin < b -> begin && !(nghttp3_max_uint64 (a -> begin , b -> begin ) <
832
827
nghttp3_min_uint64 (a -> end , b -> end ));
833
828
}
829
+
830
+ nghttp3_ksl_search_def (range_exclusive , nghttp3_ksl_range_exclusive_compar )
831
+
832
+ size_t nghttp3_ksl_range_exclusive_search (const nghttp3_ksl * ksl ,
833
+ nghttp3_ksl_blk * blk ,
834
+ const nghttp3_ksl_key * key ) {
835
+ return ksl_range_exclusive_search (ksl , blk , key );
836
+ }
837
+
838
+ int nghttp3_ksl_uint64_less (const nghttp3_ksl_key * lhs ,
839
+ const nghttp3_ksl_key * rhs ) {
840
+ return * (uint64_t * )lhs < * (uint64_t * )rhs ;
841
+ }
842
+
843
+ nghttp3_ksl_search_def (uint64_less , nghttp3_ksl_uint64_less )
844
+
845
+ size_t nghttp3_ksl_uint64_less_search (const nghttp3_ksl * ksl ,
846
+ nghttp3_ksl_blk * blk ,
847
+ const nghttp3_ksl_key * key ) {
848
+ return ksl_uint64_less_search (ksl , blk , key );
849
+ }
850
+
851
+ int nghttp3_ksl_int64_greater (const nghttp3_ksl_key * lhs ,
852
+ const nghttp3_ksl_key * rhs ) {
853
+ return * (int64_t * )lhs > * (int64_t * )rhs ;
854
+ }
855
+
856
+ nghttp3_ksl_search_def (int64_greater , nghttp3_ksl_int64_greater )
857
+
858
+ size_t nghttp3_ksl_int64_greater_search (const nghttp3_ksl * ksl ,
859
+ nghttp3_ksl_blk * blk ,
860
+ const nghttp3_ksl_key * key ) {
861
+ return ksl_int64_greater_search (ksl , blk , key );
862
+ }
0 commit comments