@@ -1440,13 +1440,14 @@ insert_int(
1440
1440
FAMObject * self ,
1441
1441
npy_int64 key ,
1442
1442
Py_ssize_t keys_pos ,
1443
- Py_hash_t hash )
1443
+ Py_hash_t hash ,
1444
+ KeysArrayType kat )
1444
1445
{
1445
1446
if (hash == -1 ) {
1446
1447
hash = int_to_hash (key );
1447
1448
}
1448
1449
// table position is not dependent on keys_pos
1449
- Py_ssize_t table_pos = lookup_hash_int (self , key , hash , self -> keys_array_type );
1450
+ Py_ssize_t table_pos = lookup_hash_int (self , key , hash , kat );
1450
1451
if (table_pos < 0 ) {
1451
1452
return -1 ;
1452
1453
}
@@ -1470,12 +1471,13 @@ insert_uint(
1470
1471
FAMObject * self ,
1471
1472
npy_uint64 key ,
1472
1473
Py_ssize_t keys_pos ,
1473
- Py_hash_t hash )
1474
+ Py_hash_t hash ,
1475
+ KeysArrayType kat )
1474
1476
{
1475
1477
if (hash == -1 ) {
1476
1478
hash = uint_to_hash (key );
1477
1479
}
1478
- Py_ssize_t table_pos = lookup_hash_uint (self , key , hash , self -> keys_array_type );
1480
+ Py_ssize_t table_pos = lookup_hash_uint (self , key , hash , kat );
1479
1481
1480
1482
if (table_pos < 0 ) {
1481
1483
return -1 ;
@@ -1500,13 +1502,14 @@ insert_double(
1500
1502
FAMObject * self ,
1501
1503
npy_double key ,
1502
1504
Py_ssize_t keys_pos ,
1503
- Py_hash_t hash )
1505
+ Py_hash_t hash ,
1506
+ KeysArrayType kat )
1504
1507
{
1505
1508
if (hash == -1 ) {
1506
1509
hash = double_to_hash (key );
1507
1510
}
1508
1511
// table position is not dependent on keys_pos
1509
- Py_ssize_t table_pos = lookup_hash_double (self , key , hash , self -> keys_array_type );
1512
+ Py_ssize_t table_pos = lookup_hash_double (self , key , hash , kat );
1510
1513
1511
1514
if (table_pos < 0 ) {
1512
1515
return -1 ;
@@ -2381,13 +2384,13 @@ fam_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
2381
2384
2382
2385
2383
2386
// This macro can be used with integer and floating point NumPy types, given an `npy_type` and a specialized `insert_func`. Uses context of `fam_init` to get `fam`, `contiguous`, `a`, `keys_size`, and `i`. An optional `post_deref` function can be supplied to transform extracted values before calling the appropriate insert function.
2384
- # define INSERT_SCALARS (npy_type , insert_func , post_deref ) \
2387
+ # define INSERT_SCALARS (npy_type , insert_func , kat , post_deref ) \
2385
2388
{ \
2386
2389
if (contiguous) { \
2387
2390
npy_type* b = (npy_type*)PyArray_DATA(a); \
2388
2391
npy_type* b_end = b + keys_size; \
2389
2392
while (b < b_end) { \
2390
- if (insert_func(fam, post_deref(*b), i, -1)) { \
2393
+ if (insert_func(fam, post_deref(*b), i, -1, kat )) { \
2391
2394
goto error; \
2392
2395
} \
2393
2396
b++; \
@@ -2399,7 +2402,8 @@ fam_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
2399
2402
if (insert_func(fam, \
2400
2403
post_deref(*(npy_type*)PyArray_GETPTR1(a, i)),\
2401
2404
i, \
2402
- -1)) { \
2405
+ -1, \
2406
+ kat)) { \
2403
2407
goto error; \
2404
2408
} \
2405
2409
} \
@@ -2513,7 +2517,7 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
2513
2517
}
2514
2518
keys_size = PyList_GET_SIZE (keys );
2515
2519
}
2516
- assert ( keys_array_type >= 0 );
2520
+
2517
2521
fam -> keys = keys ;
2518
2522
fam -> keys_array_type = keys_array_type ;
2519
2523
fam -> keys_size = keys_size ;
@@ -2530,37 +2534,37 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
2530
2534
int contiguous = PyArray_IS_C_CONTIGUOUS (a );
2531
2535
switch (keys_array_type ) {
2532
2536
case KAT_INT64 :
2533
- INSERT_SCALARS (npy_int64 , insert_int , );
2537
+ INSERT_SCALARS (npy_int64 , insert_int , keys_array_type , );
2534
2538
break ;
2535
2539
case KAT_INT32 :
2536
- INSERT_SCALARS (npy_int32 , insert_int , );
2540
+ INSERT_SCALARS (npy_int32 , insert_int , keys_array_type , );
2537
2541
break ;
2538
2542
case KAT_INT16 :
2539
- INSERT_SCALARS (npy_int16 , insert_int , );
2543
+ INSERT_SCALARS (npy_int16 , insert_int , keys_array_type , );
2540
2544
break ;
2541
2545
case KAT_INT8 :
2542
- INSERT_SCALARS (npy_int8 , insert_int , );
2546
+ INSERT_SCALARS (npy_int8 , insert_int , keys_array_type , );
2543
2547
break ;
2544
2548
case KAT_UINT64 :
2545
- INSERT_SCALARS (npy_uint64 , insert_uint , );
2549
+ INSERT_SCALARS (npy_uint64 , insert_uint , keys_array_type , );
2546
2550
break ;
2547
2551
case KAT_UINT32 :
2548
- INSERT_SCALARS (npy_uint32 , insert_uint , );
2552
+ INSERT_SCALARS (npy_uint32 , insert_uint , keys_array_type , );
2549
2553
break ;
2550
2554
case KAT_UINT16 :
2551
- INSERT_SCALARS (npy_uint16 , insert_uint , );
2555
+ INSERT_SCALARS (npy_uint16 , insert_uint , keys_array_type , );
2552
2556
break ;
2553
2557
case KAT_UINT8 :
2554
- INSERT_SCALARS (npy_uint8 , insert_uint , );
2558
+ INSERT_SCALARS (npy_uint8 , insert_uint , keys_array_type , );
2555
2559
break ;
2556
2560
case KAT_FLOAT64 :
2557
- INSERT_SCALARS (npy_double , insert_double , );
2561
+ INSERT_SCALARS (npy_double , insert_double , keys_array_type , );
2558
2562
break ;
2559
2563
case KAT_FLOAT32 :
2560
- INSERT_SCALARS (npy_float , insert_double , );
2564
+ INSERT_SCALARS (npy_float , insert_double , keys_array_type , );
2561
2565
break ;
2562
2566
case KAT_FLOAT16 :
2563
- INSERT_SCALARS (npy_half , insert_double , npy_half_to_double );
2567
+ INSERT_SCALARS (npy_half , insert_double , keys_array_type , npy_half_to_double );
2564
2568
break ;
2565
2569
case KAT_UNICODE : {
2566
2570
// Over allocate buffer by 1 so there is room for null at end. This buffer is only used in lookup();
@@ -2587,7 +2591,7 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
2587
2591
case KAT_DTps :
2588
2592
case KAT_DTfs :
2589
2593
case KAT_DTas :
2590
- INSERT_SCALARS (npy_int64 , insert_int , );
2594
+ INSERT_SCALARS (npy_int64 , insert_int , KAT_INT64 , );
2591
2595
break ;
2592
2596
default :
2593
2597
return -1 ;
0 commit comments