@@ -118,8 +118,6 @@ typedef struct A
118
118
float max_load_factor ;
119
119
void (* free )(T * );
120
120
T (* copy )(T * );
121
- size_t (* hash )(T * );
122
- int (* equal )(T * , T * );
123
121
#if CTL_USET_SECURITY_COLLCOUNTING == 4
124
122
bool is_sorted_vector ;
125
123
#elif CTL_USET_SECURITY_COLLCOUNTING == 5
@@ -144,11 +142,11 @@ static inline size_t JOIN(A, bucket_count)(A *self)
144
142
static inline size_t JOIN (I , index )(A * self , T value )
145
143
{
146
144
#ifdef CTL_USET_GROWTH_POWER2
147
- return self -> hash (& value ) & self -> bucket_max ;
145
+ return JOIN ( T , hash ) (& value ) & self -> bucket_max ;
148
146
#elif __WORDSIZE == 127
149
- return ((uint64_t ) self -> hash (& value ) * ((uint64_t ) self -> bucket_max + 1 )) >> 32 ;
147
+ return ((uint64_t ) JOIN ( T , hash ) (& value ) * ((uint64_t ) self -> bucket_max + 1 )) >> 32 ;
150
148
#else
151
- return self -> hash (& value ) % (self -> bucket_max + 1 );
149
+ return JOIN ( T , hash ) (& value ) % (self -> bucket_max + 1 );
152
150
#endif
153
151
}
154
152
@@ -322,10 +320,12 @@ JOIN(I, range)(A* container, I* begin, I* end)
322
320
}
323
321
*/
324
322
323
+ // needed for algorithm
325
324
static inline int JOIN (A , _equal )(A * self , T * a , T * b )
326
325
{
327
- ASSERT (self -> equal || !"equal undefined" );
328
- return self -> equal (a , b );
326
+ //ASSERT(JOIN(T, equal) || !"equal undefined");
327
+ (void )self ;
328
+ return JOIN (T , equal )(a , b );
329
329
}
330
330
331
331
static inline A JOIN (A , init_from )(A * copy );
@@ -518,15 +518,15 @@ static inline B **JOIN(A, _bucket_hash)(A *self, size_t hash)
518
518
static inline B * * JOIN (A , _bucket )(A * self , T value )
519
519
{
520
520
const size_t hash = JOIN (I , index )(self , value );
521
- //LOG ("_bucket %lx %% %lu => %zu\n", self-> hash(&value), self->bucket_max + 1, hash);
521
+ //LOG ("_bucket %lx %% %lu => %zu\n", JOIN(T, hash) (&value), self->bucket_max + 1, hash);
522
522
return & self -> buckets [hash ];
523
523
}
524
524
#endif
525
525
526
526
static inline size_t JOIN (A , bucket )(A * self , T value )
527
527
{
528
528
const size_t hash = JOIN (I , index )(self , value );
529
- //LOG ("bucket %lx %% %lu => %zu\n", self-> hash(&value), self->bucket_max + 1, hash);
529
+ //LOG ("bucket %lx %% %lu => %zu\n", JOIN(T, hash) (&value), self->bucket_max + 1, hash);
530
530
return hash ;
531
531
}
532
532
@@ -613,12 +613,10 @@ static inline void JOIN(A, reserve)(A *self, size_t desired_count)
613
613
JOIN (A , _rehash )(self , new_size );
614
614
}
615
615
616
- static inline A JOIN (A , init )(size_t ( * _hash )( T * ), int ( * _equal )( T * , T * ) )
616
+ static inline A JOIN (A , init )(void )
617
617
{
618
618
static A zero ;
619
619
A self = zero ;
620
- self .hash = _hash ;
621
- self .equal = _equal ;
622
620
#ifdef POD
623
621
self .copy = JOIN (A , implicit_copy );
624
622
_JOIN (A , _set_default_methods )(& self );
@@ -633,24 +631,16 @@ static inline A JOIN(A, init)(size_t (*_hash)(T *), int (*_equal)(T *, T *))
633
631
634
632
static inline A JOIN (A , init_from )(A * copy )
635
633
{
636
- static A zero ;
637
- A self = zero ;
638
- #ifdef POD
639
- self .copy = JOIN (A , implicit_copy );
640
- #else
641
- self .free = JOIN (T , free );
642
- self .copy = JOIN (T , copy );
643
- #endif
644
- self .hash = copy -> hash ;
645
- self .equal = copy -> equal ;
634
+ A self = JOIN (A , init )();
635
+ JOIN (A , _reserve )(& self , copy -> bucket_max + 1 );
646
636
return self ;
647
637
}
648
638
649
639
static inline void JOIN (A , rehash )(A * self , size_t desired_count )
650
640
{
651
641
if (desired_count == (self -> bucket_max + 1 ))
652
642
return ;
653
- A rehashed = JOIN (A , init )(self -> hash , self -> equal );
643
+ A rehashed = JOIN (A , init )();
654
644
JOIN (A , reserve )(& rehashed , desired_count );
655
645
if (LIKELY (self -> buckets && self -> size )) // if desired_count 0
656
646
{
@@ -681,7 +671,7 @@ static inline void JOIN(A, _rehash)(A *self, size_t count)
681
671
// we do allow shrink here
682
672
if (count == self -> bucket_max + 1 )
683
673
return ;
684
- A rehashed = JOIN (A , init )(self -> hash , self -> equal );
674
+ A rehashed = JOIN (A , init )();
685
675
//LOG("_rehash %zu => %zu\n", self->size, count);
686
676
JOIN (A , _reserve )(& rehashed , count );
687
677
@@ -714,7 +704,7 @@ static inline B *JOIN(A, find_node)(A *self, T value)
714
704
if (self -> size )
715
705
{
716
706
#ifdef CTL_USET_CACHED_HASH
717
- size_t hash = self -> hash (& value );
707
+ size_t hash = JOIN ( T , hash ) (& value );
718
708
B * * buckets = JOIN (A , _bucket_hash )(self , hash );
719
709
#else
720
710
B * * buckets = JOIN (A , _bucket )(self , value );
@@ -739,7 +729,7 @@ static inline B *JOIN(A, find_node)(A *self, T value)
739
729
if (n -> cached_hash != hash )
740
730
continue ;
741
731
#endif
742
- if (self -> equal (& value , & n -> value ))
732
+ if (JOIN ( T , equal ) (& value , & n -> value ))
743
733
{
744
734
#if 0 // not yet
745
735
// speedup subsequent read accesses?
@@ -802,7 +792,7 @@ static inline B **JOIN(A, push_cached)(A *self, T *value)
802
792
#endif
803
793
804
794
#ifdef CTL_USET_CACHED_HASH
805
- size_t hash = self -> hash (value );
795
+ size_t hash = JOIN ( T , hash ) (value );
806
796
B * * buckets = JOIN (A , _bucket_hash )(self , hash );
807
797
JOIN (B , push )(buckets , JOIN (B , init_cached )(* value , hash ));
808
798
#else
@@ -899,7 +889,7 @@ static inline I JOIN(A, emplace_hint)(I *pos, T *value)
899
889
if (!JOIN (I , done )(pos ))
900
890
{
901
891
#ifdef CTL_USET_CACHED_HASH
902
- size_t hash = self -> hash (value );
892
+ size_t hash = JOIN ( T , hash ) (value );
903
893
B * * buckets = JOIN (A , _bucket_hash )(self , hash );
904
894
#else
905
895
B * * buckets = JOIN (A , _bucket )(self , * value );
@@ -924,7 +914,7 @@ static inline I JOIN(A, emplace_hint)(I *pos, T *value)
924
914
if (n -> cached_hash != hash )
925
915
continue ;
926
916
#endif
927
- if (self -> equal (value , & n -> value ))
917
+ if (JOIN ( T , equal ) (value , & n -> value ))
928
918
{
929
919
FREE_VALUE (self , * value );
930
920
return JOIN (I , iter )(self , n );
@@ -1060,7 +1050,7 @@ static inline void JOIN(A, _linked_erase)(A *self, B **bucket, B *n, B *prev, B
1060
1050
static inline void JOIN (A , erase )(A * self , T value )
1061
1051
{
1062
1052
#ifdef CTL_USET_CACHED_HASH
1063
- size_t hash = self -> hash (& value );
1053
+ size_t hash = JOIN ( T , hash ) (& value );
1064
1054
B * * buckets = JOIN (A , _bucket_hash )(self , hash );
1065
1055
#else
1066
1056
B * * buckets = JOIN (A , _bucket )(self , value );
@@ -1078,7 +1068,7 @@ static inline void JOIN(A, erase)(A *self, T value)
1078
1068
continue ;
1079
1069
}
1080
1070
#endif
1081
- if (self -> equal (& value , & n -> value ))
1071
+ if (JOIN ( T , equal ) (& value , & n -> value ))
1082
1072
{
1083
1073
JOIN (A , _linked_erase )(self , buckets , n , prev , next );
1084
1074
break ;
@@ -1115,7 +1105,7 @@ static inline size_t JOIN(A, erase_if)(A *self, int (*_match)(T *))
1115
1105
static inline A JOIN (A , copy )(A * self )
1116
1106
{
1117
1107
// LOG ("copy\norig size: %lu\n", self->size);
1118
- A other = JOIN (A , init )(self -> hash , self -> equal );
1108
+ A other = JOIN (A , init )();
1119
1109
JOIN (A , _reserve )(& other , self -> bucket_max + 1 );
1120
1110
foreach (A , self , it )
1121
1111
{
@@ -1154,7 +1144,7 @@ static inline void JOIN(A, erase_generic)(A* self, GI *range)
1154
1144
1155
1145
static inline A JOIN (A , union )(A * a , A * b )
1156
1146
{
1157
- A self = JOIN (A , init )(a -> hash , a -> equal );
1147
+ A self = JOIN (A , init )();
1158
1148
JOIN (A , _reserve )(& self , 1 + MAX (a -> bucket_max , b -> bucket_max ));
1159
1149
foreach (A , a , it1 )
1160
1150
JOIN (A , insert )(& self , self .copy (it1 .ref ));
@@ -1182,7 +1172,7 @@ static inline A JOIN(A, union_range)(I *r1, GI *r2)
1182
1172
1183
1173
static inline A JOIN (A , intersection )(A * a , A * b )
1184
1174
{
1185
- A self = JOIN (A , init )(a -> hash , a -> equal );
1175
+ A self = JOIN (A , init )();
1186
1176
foreach (A , a , it )
1187
1177
if (JOIN (A , find_node )(b , * it .ref ))
1188
1178
JOIN (A , insert )(& self , self .copy (it .ref ));
@@ -1192,7 +1182,7 @@ static inline A JOIN(A, intersection)(A *a, A *b)
1192
1182
static inline A JOIN (A , intersection_range )(I * r1 , GI * r2 )
1193
1183
{
1194
1184
A * a = r1 -> container ;
1195
- A self = JOIN (A , init )(a -> hash , a -> equal );
1185
+ A self = JOIN (A , init )();
1196
1186
void (* next2 )(struct I * ) = r2 -> vtable .next ;
1197
1187
T * (* ref2 )(struct I * ) = r2 -> vtable .ref ;
1198
1188
int (* done2 )(struct I * ) = r2 -> vtable .done ;
@@ -1214,7 +1204,7 @@ static inline A JOIN(A, intersection_range)(I *r1, GI *r2)
1214
1204
1215
1205
static inline A JOIN (A , difference )(A * a , A * b )
1216
1206
{
1217
- A self = JOIN (A , init )(a -> hash , a -> equal );
1207
+ A self = JOIN (A , init )();
1218
1208
foreach (A , a , it )
1219
1209
if (!JOIN (A , find_node )(b , * it .ref ))
1220
1210
JOIN (A , insert )(& self , self .copy (it .ref ));
0 commit comments