3636
3737static nghttp3_ksl_blk null_blk = {{{NULL , NULL , 0 , 0 , {0 }}}};
3838
39- nghttp3_objalloc_def (ksl_blk , nghttp3_ksl_blk , oplent );
39+ nghttp3_objalloc_def (ksl_blk , nghttp3_ksl_blk , oplent )
4040
4141static size_t ksl_nodelen (size_t keylen ) {
4242 assert (keylen >= sizeof (uint64_t ));
@@ -59,7 +59,8 @@ static void ksl_node_set_key(nghttp3_ksl *ksl, nghttp3_ksl_node *node,
5959}
6060
6161void 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 ) {
6364 size_t nodelen = ksl_nodelen (keylen );
6465
6566 nghttp3_objalloc_init (& ksl -> blkalloc ,
@@ -68,6 +69,7 @@ void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
6869 ksl -> head = NULL ;
6970 ksl -> front = ksl -> back = NULL ;
7071 ksl -> compar = compar ;
72+ ksl -> search = search ;
7173 ksl -> n = 0 ;
7274 ksl -> keylen = keylen ;
7375 ksl -> nodelen = nodelen ;
@@ -274,20 +276,6 @@ static void ksl_insert_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i,
274276 ++ blk -> n ;
275277}
276278
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-
291279int nghttp3_ksl_insert (nghttp3_ksl * ksl , nghttp3_ksl_it * it ,
292280 const nghttp3_ksl_key * key , void * data ) {
293281 nghttp3_ksl_blk * blk ;
@@ -312,7 +300,7 @@ int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
312300 blk = ksl -> head ;
313301
314302 for (;;) {
315- i = ksl_search (ksl , blk , key , ksl -> compar );
303+ i = ksl -> search (ksl , blk , key );
316304
317305 if (blk -> leaf ) {
318306 if (i < blk -> n &&
@@ -571,7 +559,7 @@ int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
571559 }
572560
573561 for (;;) {
574- i = ksl_search (ksl , blk , key , ksl -> compar );
562+ i = ksl -> search (ksl , blk , key );
575563
576564 if (i == blk -> n ) {
577565 if (it ) {
@@ -642,12 +630,12 @@ int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
642630
643631nghttp3_ksl_it nghttp3_ksl_lower_bound (const nghttp3_ksl * ksl ,
644632 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 );
646634}
647635
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 ,
649637 const nghttp3_ksl_key * key ,
650- nghttp3_ksl_compar compar ) {
638+ nghttp3_ksl_search search ) {
651639 nghttp3_ksl_blk * blk = ksl -> head ;
652640 nghttp3_ksl_it it ;
653641 size_t i ;
@@ -658,7 +646,7 @@ nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(const nghttp3_ksl *ksl,
658646 }
659647
660648 for (;;) {
661- i = ksl_search (ksl , blk , key , compar );
649+ i = search (ksl , blk , key );
662650
663651 if (blk -> leaf ) {
664652 if (i == blk -> n && blk -> next ) {
@@ -702,7 +690,7 @@ void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key,
702690 assert (ksl -> head );
703691
704692 for (;;) {
705- i = ksl_search (ksl , blk , old_key , ksl -> compar );
693+ i = ksl -> search (ksl , blk , old_key );
706694
707695 assert (i < blk -> n );
708696 node = nghttp3_ksl_nth_node (ksl , blk , i );
@@ -825,9 +813,50 @@ int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
825813 return a -> begin < b -> begin ;
826814}
827815
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+
828823int nghttp3_ksl_range_exclusive_compar (const nghttp3_ksl_key * lhs ,
829824 const nghttp3_ksl_key * rhs ) {
830825 const nghttp3_range * a = lhs , * b = rhs ;
831826 return a -> begin < b -> begin && !(nghttp3_max_uint64 (a -> begin , b -> begin ) <
832827 nghttp3_min_uint64 (a -> end , b -> end ));
833828}
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