File: Dkhashext.c

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (707 lines) | stat: -rw-r--r-- 20,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
/*
 *  Dkhashext.c
 *
 *  $Id$
 *
 *  Hashing
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2018 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#include "Dk.h"

/* Aligning failed - not needed since keybytes/databytes are void * (PmN) */
/* But it's inevitable for 64-bit platforms with structures as hash data * (GK) */
#undef NEXT4
#define NEXT4(X)	_RNDUP((X), SIZEOF_VOID_P)


#define memcpy_8(target, source, len) \
  {if (sizeof (caddr_t) == len) *(caddr_t*)(target) = *(caddr_t*)(source); \
  else memcpy (target, source, len);}

#define memcpy_8c(target, source, len) \
  {if (sizeof (caddr_t) == len) *(caddr_t*)(target) = *(caddr_t*)(source); \
    else if (len) memcpy (target, source, len);}



caddr_t
id_hash_get (id_hash_t * ht, caddr_t key)
{
  id_hashed_key_t inx = ht->ht_hash_func (key);
  ID_HASHED_KEY_CHECK (inx);
  inx = (inx & ID_HASHED_KEY_MASK) % ht->ht_buckets;

  if (BUCKET_IS_EMPTY (BUCKET (ht, inx), ht))
    return ((caddr_t) NULL);
  if (ht->ht_cmp (BUCKET (ht, inx), key))
    return (BUCKET (ht, inx) + ht->ht_data_inx);
  else
    {
      char *ext = BUCKET_OVERFLOW (BUCKET (ht, inx), ht);
      while (ext)
	{
	  if (ht->ht_cmp (ext, key))
	    return (ext + ht->ht_data_inx);
	  ext = BUCKET_OVERFLOW (ext, ht);
	}
    }
  return ((caddr_t) NULL);
}


caddr_t
id_hash_get_with_hash_number (id_hash_t * ht, caddr_t key, id_hashed_key_t inx)
{
  ID_HASHED_KEY_CHECK (inx);
  inx = (inx & ID_HASHED_KEY_MASK) % ht->ht_buckets;

  if (BUCKET_IS_EMPTY (BUCKET (ht, inx), ht))
    return ((caddr_t) NULL);
  if (ht->ht_cmp (BUCKET (ht, inx), key))
    return (BUCKET (ht, inx) + ht->ht_data_inx);
  else
    {
      char *ext = BUCKET_OVERFLOW (BUCKET (ht, inx), ht);
      while (ext)
	{
	  if (ht->ht_cmp (ext, key))
	    return (ext + ht->ht_data_inx);
	  ext = BUCKET_OVERFLOW (ext, ht);
	}
    }
  return ((caddr_t) NULL);
}


caddr_t
id_hash_get_with_ctx (id_hash_t * ht, caddr_t key, void *ctx)
{
  id_hashed_key_t inx = ht->ht_hash_func (key);
  cmp_func_with_ctx_t cmp = (cmp_func_with_ctx_t) ((void *) ht->ht_cmp);
  ID_HASHED_KEY_CHECK (inx);
  inx = (inx & ID_HASHED_KEY_MASK) % ht->ht_buckets;

  if (BUCKET_IS_EMPTY (BUCKET (ht, inx), ht))
    return ((caddr_t) NULL);
  if (cmp (BUCKET (ht, inx), key, ctx))
    return (BUCKET (ht, inx) + ht->ht_data_inx);
  else
    {
      char *ext = BUCKET_OVERFLOW (BUCKET (ht, inx), ht);
      while (ext)
	{
	  if (ht->ht_cmp (ext, key))
	    return (ext + ht->ht_data_inx);
	  ext = BUCKET_OVERFLOW (ext, ht);
	}
    }
  return ((caddr_t) NULL);
}


caddr_t
id_hash_get_key (id_hash_t * ht, caddr_t key)
{
  caddr_t place = id_hash_get (ht, key);
  if (!place)
    return NULL;
  return (place - ht->ht_key_length);
}


caddr_t
id_hash_get_key_by_place (id_hash_t * ht, caddr_t place)
{
  if (!place)
    return NULL;
  return (place - ht->ht_key_length);
}


void
id_hash_iterator (id_hash_iterator_t * hit, id_hash_t * ht)
{
  hit->hit_hash = ht;
  hit->hit_bucket = 0;
  hit->hit_chilum = NULL;
}


int
hit_next (id_hash_iterator_t * hit, char **key, char **data)
{
  id_hash_t *ht = hit->hit_hash;
  while (((uint32) hit->hit_bucket) < ht->ht_buckets)
    {
      if (hit->hit_chilum)
	{
	  *key = hit->hit_chilum;
	  *data = (*key) + ht->ht_key_length;
	  hit->hit_chilum = BUCKET_OVERFLOW (hit->hit_chilum, ht);
	  if (!hit->hit_chilum)
	    hit->hit_bucket++;
	  return 1;
	}
      else
	{
	  char *ov = BUCKET_OVERFLOW (BUCKET (ht, hit->hit_bucket), ht);

	  if (ov == (char *) -1L)
	    {
	      hit->hit_bucket++;
	      continue;
	    }
	  *key = BUCKET (ht, hit->hit_bucket);
	  *data = (*key) + ht->ht_key_length;
	  if (ov)
	    hit->hit_chilum = ov;
	  else
	    hit->hit_bucket++;
	  return 1;
	}
    }
  return 0;
}


id_hashed_key_t
strhash (char *strp)
{
  char *str = *(char **) strp;
  id_hashed_key_t h;
  NTS_BUFFER_HASH (h, str);
  return (h & ID_HASHED_KEY_MASK);
}


id_hashed_key_t
strhashcase (char *strp)
{
  char *str = *(char **) strp;
  id_hashed_key_t h = 1;
  while (*str)
    {
      h = h + h * (*str | ('A' ^ 'a'));
      str++;
    }
  return (h & ID_HASHED_KEY_MASK);
}


id_hashed_key_t
lenmemhash (char *strp)
{
  lenmem_t *lm = (lenmem_t *) strp;
  size_t len = lm->lm_length;
  id_hashed_key_t h;
  BYTE_BUFFER_HASH (h, lm->lm_memblock, len);
  return (h & ID_HASHED_KEY_MASK);
}


id_hashed_key_t
voidptrhash (char *voidp)
{
  voidp = (char *) (((char **) voidp)[0]);
  return (uint32) (((ptrlong) voidp ^ (((ptrlong) voidp) >> 31)) & ID_HASHED_KEY_MASK);
}


int
strhashcmp (char *x, char *y)
{
  return 0 == strcmp (((char **) x)[0], ((char **) y)[0]);
}


int
strhashcasecmp (char *x, char *y)
{
  x = (char *) (((char **) x)[0]);
  y = (char *) (((char **) y)[0]);
  while (x[0])
    {
      if (((int) (x[0]) | ('A' ^ 'a')) ^ ((int) (y[0]) | ('A' ^ 'a')))
	return 0;
      x++;
      y++;
    }
  return ('\0' == y[0]) ? 1 : 0;
}


int
lenmemhashcmp (char *x, char *y)
{
  lenmem_t *lmx = (lenmem_t *) x;
  lenmem_t *lmy = (lenmem_t *) y;
  size_t len = lmx->lm_length;
  if (lmy->lm_length != len)
    return 0;
  return (0 == memcmp (lmx->lm_memblock, lmy->lm_memblock, len));
}


int
voidptrhashcmp (char *x, char *y)
{
  x = (char *) (((char **) x)[0]);
  y = (char *) (((char **) y)[0]);
  return ((y == x) ? 1 : 0);
}


id_hashed_key_t
boxint_hash (char *x)
{
  union
  {
    boxint k;
    struct
    {
      int32 n1;
      int32 n2;
    } k32;
  } n;
  n.k = *(boxint *) x;
  return 0xfffffff & (n.k32.n1 ^ n.k32.n2);
}


int
boxint_hashcmp (char *x, char *y)
{
  boxint k1 = *(boxint *) x, k2 = *(boxint *) y;
  return k1 == k2 ? 1 : 0;
}

box_hash_func_t dtp_hash_func[256];

extern id_hashed_key_t rdf_box_hash (caddr_t box);

id_hashed_key_t
box_hash (caddr_t box)
{
  id_hashed_key_t h;
  dtp_t dtp;
  if (!IS_BOX_POINTER (box))
    return ((uint32) ((ptrlong) box)) & ID_HASHED_KEY_MASK;
  dtp = box_tag (box);
  if (dtp_hash_func[dtp])
    return ID_HASHED_KEY_MASK & dtp_hash_func[dtp] (box);
  switch (dtp)
    {
    case DV_LONG_INT:
      {
	uint64 i = *(uint64*)box;
	return ((i >> 32) ^ i) & ID_HASHED_KEY_MASK;
      }
    case DV_IRI_ID:
    case DV_IRI_ID_8:
      if (NULL == box)
	return 0;
      return ((*(unsigned int64 *) box) & ID_HASHED_KEY_MASK);

    case DV_ARRAY_OF_POINTER:
    case DV_LIST_OF_POINTER:
    case DV_ARRAY_OF_XQVAL:
    case DV_XTREE_HEAD:
    case DV_XTREE_NODE:
      {
	int inx, len = box_length (box) / sizeof (caddr_t);
	h = 0;
	for (inx = 0; inx < len; inx++)
	  h = ROL (h) ^ box_hash (((caddr_t *) box)[inx]);
	return h & ID_HASHED_KEY_MASK;
      }

    case DV_UNAME:
      DV_UNAME_BOX_HASH (h, box);
      return h & ID_HASHED_KEY_MASK;

    default:
      {
	uint32 len = box_length_inline (box);
	if (len > 0)
	  BYTE_BUFFER_HASH (h, box, len - 1); /* was BYTE_BUFFER_HASH2 but it break xslt compare with UNAMEs etc. */
	else
	  h = 0;
	return h & ID_HASHED_KEY_MASK;
      }
    }
}

id_hashed_key_t
box_hash_cut (caddr_t box, int depth)
{
  id_hashed_key_t h;
  dtp_t dtp;
  if (!IS_BOX_POINTER (box))
    return ((uint32) ((ptrlong) box)) & ID_HASHED_KEY_MASK;
  dtp = box_tag (box);
  if (dtp_hash_func[dtp])
    return ID_HASHED_KEY_MASK & dtp_hash_func[dtp] (box);
  switch (dtp)
    {
    case DV_LONG_INT:
      return ((*(boxint *) box) & ID_HASHED_KEY_MASK);
    case DV_IRI_ID:
    case DV_IRI_ID_8:
      if (NULL == box)
        return 0;
      return ((*(unsigned int64 *) box) & ID_HASHED_KEY_MASK);
    case DV_ARRAY_OF_POINTER:
    case DV_LIST_OF_POINTER:
    case DV_ARRAY_OF_XQVAL:
    case DV_XTREE_HEAD:
    case DV_XTREE_NODE:
      {
        int inx, len = box_length (box) / sizeof (caddr_t);
        if (0 >= depth)
          return ((id_hashed_key_t)len * dtp) & ID_HASHED_KEY_MASK;
        h = 0;
        depth--;
        for (inx = 0; inx < len; inx++)
          h = ROL (h) ^ box_hash_cut (((caddr_t *) box)[inx], depth);
        return h & ID_HASHED_KEY_MASK;
      }
    case DV_UNAME:
      DV_UNAME_BOX_HASH (h, box);
      return h & ID_HASHED_KEY_MASK;
    default:
      {
        uint32 len = box_length_inline (box);
        if (len > 0)
          BYTE_BUFFER_HASH (h, box, len - 1);
        else
          h = 0;
        return h & ID_HASHED_KEY_MASK;
      }
    }
}

void dtp_set_cmp (dtp_t dtp, box_hash_cmp_func_t f);
void dtp_set_strong_cmp (dtp_t dtp, box_hash_cmp_func_t f);


void
dk_dtp_register_hash (dtp_t dtp, box_hash_func_t hf, box_hash_cmp_func_t cmp, box_hash_cmp_func_t strong_cmp)
{
  dtp_hash_func[dtp] = hf;
  dtp_set_cmp (dtp, cmp);
  dtp_set_strong_cmp (dtp, strong_cmp);
}


id_hashed_key_t
treehash (char *strp)
{
  char *str = *(char **) strp;
  return (box_hash (str));
}

extern int box_strong_equal (cbox_t b1, cbox_t b2);

int
treehashcmp (char *x, char *y)
{
  return (box_strong_equal (*((caddr_t *) x), *((caddr_t *) y)));
}


/* Allocator-dependent functions, dk_alloc versions */

#define DBG_HASHEXT_NAME(name) DBG_NAME(name)
#define DBG_HASHEXT_ALLOC(SZ) DK_ALLOC((SZ))
#define DBG_HASHEXT_FREE(BOX,SZ) DK_FREE((BOX),(SZ))

#include "Dkhashext_template.c"

caddr_t
DBG_NAME (box_dv_dict_hashtable) (DBG_PARAMS id_hashed_key_t buckets)
{
  id_hash_t *res = (id_hash_t *) DBG_NAME (dk_alloc_box) (DBG_ARGS sizeof (id_hash_t), DV_DICT_HASHTABLE);
  ID_HASH_ALLOCATE_INTERNALS (res, buckets, sizeof (caddr_t), sizeof (caddr_t), treehash, treehashcmp);
  res->ht_dict_version = 1;
  res->ht_rehash_threshold = 50;
  return (caddr_t) res;
}


caddr_t
DBG_NAME (box_dv_dict_iterator) (DBG_PARAMS caddr_t ht_box)
{
  id_hash_iterator_t *res = (id_hash_iterator_t *) DBG_NAME (dk_alloc_box) (DBG_ARGS sizeof (id_hash_iterator_t), DV_DICT_ITERATOR);
  id_hash_t *ht = (id_hash_t *) ht_box;
  res->hit_hash = ht;
  res->hit_bucket = -1;
  res->hit_chilum = (char *)(-1);
  if (NULL != ht)
    {
      if (NULL != ht->ht_mutex)
	mutex_enter (ht->ht_mutex);
      res->hit_dict_version = ht->ht_dict_version;
      ht->ht_dict_refctr += 1;
      if (NULL != ht->ht_mutex)
	mutex_leave (ht->ht_mutex);
    }
  else
    res->hit_dict_version = 0;
  return (caddr_t) res;
}


caddr_t
box_dict_hashtable_copy_hook (caddr_t orig)
{
#ifdef MALLOC_DEBUG
  char *file = __FILE__;
  int line = __LINE__;
#endif
  id_hashed_key_t buckets;
  id_hash_t *orig_dict = (id_hash_t *) orig;
  id_hash_t *res;
  caddr_t key, val;
  id_hash_iterator_t hit;
#ifndef NDEBUG
  if (0 >= orig_dict->ht_dict_refctr)
    GPF_T;
#endif
  res = (id_hash_t *) dk_alloc_box (sizeof (id_hash_t), DV_DICT_HASHTABLE);
  if (orig_dict->ht_mutex)
    mutex_enter (orig_dict->ht_mutex);
  buckets = (((id_hash_t *) orig_dict)->ht_inserts - ((id_hash_t *) orig_dict)->ht_deletes);
  if (buckets < orig_dict->ht_buckets)
    buckets = orig_dict->ht_buckets;
  else
    buckets = hash_nextprime (buckets);
  ID_HASH_ALLOCATE_INTERNALS (res, buckets, sizeof (caddr_t), sizeof (caddr_t), treehash, treehashcmp);
  res->ht_dict_refctr = 0;
  res->ht_dict_version = 1;
  res->ht_dict_mem_in_use = orig_dict->ht_dict_mem_in_use;
  res->ht_dict_max_entries = orig_dict->ht_dict_max_entries;
  res->ht_dict_max_mem_in_use = orig_dict->ht_dict_max_mem_in_use;
  id_hash_iterator (&hit, orig_dict);
  while (hit_next (&hit, &key, &val))
    {
      caddr_t key_copy, val_copy;
      key_copy = box_copy_tree (((caddr_t *)key)[0]);
      val_copy = box_copy_tree (((caddr_t *)val)[0]);
      id_hash_set (res, (caddr_t) (&key_copy), (caddr_t) (&val_copy));
    }
  if (orig_dict->ht_mutex)
    {
      res->ht_mutex = mutex_allocate ();
      mutex_leave (orig_dict->ht_mutex);
    }
  return (caddr_t) res;
}


int
box_dict_hashtable_destr_hook (caddr_t dict)
{
#ifdef MALLOC_DEBUG
  char *file = __FILE__;
  int line = __LINE__;
#endif
  caddr_t *key, *val;
  id_hash_t *ht = (id_hash_t *) dict;
  id_hash_iterator_t hit;
#ifndef NDEBUG
  if (0 != ((id_hash_t *) (dict))->ht_dict_refctr)
    GPF_T1 ("Destructor on hashtable with references");
#endif
  if (ht->ht_free_hook)
    ht->ht_free_hook (ht);
  else
    {
      id_hash_iterator (&hit, (id_hash_t *) (dict));
      while (!ht->ht_mp && hit_next (&hit, (caddr_t *) (&key), (caddr_t *) (&val)))
	{
	  dk_free_tree (key[0]);
	  dk_free_tree (val[0]);
	}
    }
  if (ht->ht_mp)
    mp_free ((mem_pool_t*)ht->ht_mp);
  id_hash_clear ((id_hash_t *) (dict));
  ID_HASH_FREE_INTERNALS ((id_hash_t *) (dict));
  return 0;
}


caddr_t
box_dict_iterator_copy_hook (caddr_t orig_iter)
{
  id_hash_iterator_t *org = (id_hash_iterator_t *) orig_iter;
  id_hash_iterator_t *res = (id_hash_iterator_t *) dk_alloc_box (sizeof (id_hash_iterator_t), DV_DICT_ITERATOR);
  res->hit_hash = org->hit_hash;
  res->hit_bucket = org->hit_bucket;
  res->hit_chilum = org->hit_chilum;
  res->hit_dict_version = org->hit_dict_version;
  if (org->hit_hash)
    {
#ifndef NDEBUG
      if (0 >= org->hit_hash->ht_dict_refctr)
	GPF_T;
#endif
      if ((org->hit_hash->ht_mutex) && (ID_HASH_LOCK_REFCOUNT != org->hit_hash->ht_dict_refctr))
	{
	  mutex_enter (org->hit_hash->ht_mutex);
	  org->hit_hash->ht_dict_refctr += 1;
	  mutex_leave (org->hit_hash->ht_mutex);
	}
      else
	org->hit_hash->ht_dict_refctr += 1;
    }
  return (caddr_t) res;
}


int
box_dict_iterator_destr_hook (caddr_t iter)
{
  id_hash_iterator_t *hit = (id_hash_iterator_t *) iter;
  if ((hit->hit_hash) && (ID_HASH_LOCK_REFCOUNT != hit->hit_hash->ht_dict_refctr))
    {
      dk_mutex_t *mtx = hit->hit_hash->ht_mutex;
#ifndef NDEBUG
      if (0 >= hit->hit_hash->ht_dict_refctr)
	GPF_T;
#endif
      if (NULL != mtx)
	{
	  mutex_enter (mtx);
	  hit->hit_hash->ht_dict_refctr -= 1;
	  if (0 == hit->hit_hash->ht_dict_refctr)
	    {
	      dk_free_box ((caddr_t) (hit->hit_hash));
	      mutex_leave (mtx);
	      mutex_free (mtx);
	    }
	  else
	    mutex_leave (mtx);
	}
      else
	{
	  hit->hit_hash->ht_dict_refctr -= 1;
	  if (0 == hit->hit_hash->ht_dict_refctr)
	    dk_free_box ((caddr_t) (hit->hit_hash));
	}
    }
  return 0;
}


void
id_hash_set_rehash_pct (id_hash_t * ht, uint32 pct)
{
  ht->ht_rehash_threshold = pct;
}


#undef DBG_HASHEXT_NAME
#undef DBG_HASHEXT_ALLOC
#undef DBG_HASHEXT_FREE


/* Allocator-dependent functions, t_alloc versions */

#ifdef MALLOC_DEBUG
#define DBG_HASHEXT_NAME(name) dbg_t_##name
#define DBG_HASHEXT_ALLOC(SZ) dbg_mp_alloc_box (DBG_ARGS THR_TMP_POOL, (SZ), DV_NON_BOX)
#else
#define DBG_HASHEXT_NAME(name) t_##name
#define DBG_HASHEXT_ALLOC(SZ) mp_alloc_box_ni (THR_TMP_POOL, (SZ), DV_NON_BOX)
#endif
#define DBG_HASHEXT_FREE(BOX,SZ)
#define FROM_POOL
#include "Dkhashext_template.c"
#undef FROM_POOL
#undef DBG_HASHEXT_NAME
#undef DBG_HASHEXT_ALLOC
#undef DBG_HASHEXT_FREE

/* Original signatures should exist for exe-exported functions */
#ifdef MALLOC_DEBUG
#undef id_hash_allocate
id_hash_t * id_hash_allocate (id_hashed_key_t buckets, int keybytes, int databytes, hash_func_t hf, cmp_func_t cf) { return dbg_id_hash_allocate (__FILE__, __LINE__, buckets, keybytes, databytes, hf, cf); }
#undef id_hash_set
void id_hash_set (id_hash_t * ht, caddr_t key, caddr_t data) { dbg_id_hash_set (__FILE__, __LINE__, ht, key, data); }
#undef id_hash_add_new
caddr_t id_hash_add_new (id_hash_t * ht, caddr_t key, caddr_t data) { return dbg_id_hash_add_new (__FILE__, __LINE__, ht, key, data); }
#undef id_hash_set_with_hash_number
void id_hash_set_with_hash_number (id_hash_t * ht, caddr_t key, caddr_t data, id_hashed_key_t inx) { dbg_id_hash_set_with_hash_number (__FILE__, __LINE__, ht, key, data, inx); }
#undef box_dv_dict_hashtable
caddr_t box_dv_dict_hashtable (id_hashed_key_t buckets) { return dbg_box_dv_dict_hashtable (__FILE__, __LINE__, buckets); }
#undef box_dv_dict_iterator
caddr_t box_dv_dict_iterator (caddr_t ht) { return dbg_box_dv_dict_iterator (__FILE__, __LINE__, ht); }
#undef id_hash_free
void id_hash_free (id_hash_t * hash) { dbg_id_hash_free (__FILE__, __LINE__, hash); }
#undef id_hash_clear
void id_hash_clear (id_hash_t * hash) { dbg_id_hash_clear (__FILE__, __LINE__, hash); }
#undef id_hash_rehash
void id_hash_rehash (id_hash_t * ht, uint32 new_sz) { dbg_id_hash_rehash (__FILE__, __LINE__, ht, new_sz); }
#undef id_hash_remove
int id_hash_remove (id_hash_t * ht, caddr_t key) { return dbg_id_hash_remove (__FILE__, __LINE__, ht, key); }
#undef id_hash_get_and_remove
int id_hash_get_and_remove (id_hash_t * ht, caddr_t key, caddr_t found_key, caddr_t found_data) { return dbg_id_hash_get_and_remove (__FILE__, __LINE__, ht, key, found_key, found_data); }
#undef id_hash_remove_rnd
int id_hash_remove_rnd (id_hash_t * ht, int inx, caddr_t key, caddr_t data) { return dbg_id_hash_remove_rnd (__FILE__, __LINE__, ht, inx, key, data); }
#undef id_str_hash_create
id_hash_t * id_str_hash_create (id_hashed_key_t buckets) { return dbg_id_str_hash_create (__FILE__, __LINE__, buckets); }
#undef id_strcase_hash_create
id_hash_t * id_strcase_hash_create (id_hashed_key_t buckets) { return dbg_id_strcase_hash_create (__FILE__, __LINE__, buckets); }
#undef id_hash_copy
void id_hash_copy (id_hash_t * to, id_hash_t * from) { dbg_id_hash_copy (__FILE__, __LINE__, to, from); }
#undef id_tree_hash_create
id_hash_t * id_tree_hash_create (id_hashed_key_t buckets) { return dbg_id_tree_hash_create (__FILE__, __LINE__, buckets); }
#undef t_id_hash_allocate
id_hash_t * t_id_hash_allocate (id_hashed_key_t buckets, int keybytes, int databytes, hash_func_t hf, cmp_func_t cf) { return dbg_t_id_hash_allocate (__FILE__, __LINE__, buckets, keybytes, databytes, hf, cf); }
#undef t_id_hash_set
void t_id_hash_set (id_hash_t * ht, caddr_t key, caddr_t data) { dbg_t_id_hash_set (__FILE__, __LINE__, ht, key, data); }
#undef t_id_hash_add_new
caddr_t t_id_hash_add_new (id_hash_t * ht, caddr_t key, caddr_t data) { return dbg_t_id_hash_add_new (__FILE__, __LINE__, ht, key, data); }
#undef t_id_hash_set_with_hash_number
void t_id_hash_set_with_hash_number (id_hash_t * ht, caddr_t key, caddr_t data, id_hashed_key_t inx) { dbg_t_id_hash_set_with_hash_number (__FILE__, __LINE__, ht, key, data, inx); }
#undef t_id_hash_free
void t_id_hash_free (id_hash_t * hash) { dbg_t_id_hash_free (__FILE__, __LINE__, hash); }
#undef t_id_hash_clear
void t_id_hash_clear (id_hash_t * hash) { dbg_t_id_hash_clear (__FILE__, __LINE__, hash); }
#undef t_id_hash_rehash
void t_id_hash_rehash (id_hash_t * ht, uint32 new_sz) { dbg_t_id_hash_rehash (__FILE__, __LINE__, ht, new_sz); }
#undef t_id_hash_remove
int t_id_hash_remove (id_hash_t * ht, caddr_t key) { return dbg_t_id_hash_remove (__FILE__, __LINE__, ht, key); }
#undef t_id_hash_get_and_remove
int t_id_hash_get_and_remove (id_hash_t * ht, caddr_t key, caddr_t found_key, caddr_t found_data) { return dbg_t_id_hash_get_and_remove (__FILE__, __LINE__, ht, key, found_key, found_data); }
#undef t_id_hash_remove_rnd
int t_id_hash_remove_rnd (id_hash_t * ht, int inx, caddr_t key, caddr_t data) { return dbg_t_id_hash_remove_rnd (__FILE__, __LINE__, ht, inx, key, data); }
#undef t_id_str_hash_create
id_hash_t * t_id_str_hash_create (id_hashed_key_t buckets) { return dbg_t_id_str_hash_create (__FILE__, __LINE__, buckets); }
#undef t_id_strcase_hash_create
id_hash_t * t_id_strcase_hash_create (id_hashed_key_t buckets) { return dbg_t_id_strcase_hash_create (__FILE__, __LINE__, buckets); }
#undef t_id_hash_copy
void t_id_hash_copy (id_hash_t * to, id_hash_t * from) { dbg_t_id_hash_copy (__FILE__, __LINE__, to, from); }
#undef t_id_tree_hash_create
id_hash_t * t_id_tree_hash_create (id_hashed_key_t buckets) { return dbg_t_id_tree_hash_create (__FILE__, __LINE__, buckets); }
#endif