25
25
#define RABIN_SHIFT 23
26
26
#define RABIN_WINDOW 16
28
/* The hash map is sized to put 4 entries per bucket, this gives us 2 blank
30
33
static const unsigned int T[256] = {
31
34
0x00000000, 0xab59b4d1, 0x56b369a2, 0xfdeadd73, 0x063f6795, 0xad66d344,
576
579
/* Copy any of the old entries across */
577
580
/* Would we rather use memcpy? */
578
581
if (hmask == old_index->hash_mask) {
580
582
for (entry = old_index->hash[i];
581
entry < old_index->hash[i+1];
583
entry < old_index->hash[i+1] && entry->ptr != NULL;
583
if (entry->ptr == NULL) {
586
} else if (found_null) {
587
fprintf(stderr, "Found a non-null entry after a"
593
585
assert((entry->val & hmask) == i);
594
586
*packed_entry++ = *entry;
599
591
* spread across the new locations.
601
593
j = i & old_index->hash_mask;
603
594
for (entry = old_index->hash[j];
604
entry < old_index->hash[j+1];
595
entry < old_index->hash[j+1] && entry->ptr != NULL;
606
if (entry->ptr == NULL) {
609
} else if (found_null) {
610
fprintf(stderr, "Found a non-null entry after a"
612
" offset %x for new offset %x"
616
597
assert((entry->val & old_index->hash_mask) == j);
617
if (!(j == i || j + old_index->hash_mask + 1 == i)) {
618
fprintf(stderr, "Old hash entry %x"
619
" doesn't fit with new %x\n"
620
"old_mask: %x new_mask: %x\n",
621
j, i, old_index->hash_mask, hmask);
598
// if (!(j == i || j + old_index->hash_mask + 1 == i)) {
599
// fprintf(stderr, "Old hash entry %x"
600
// " doesn't fit with new %x\n"
601
// "old_mask: %x new_mask: %x\n",
602
// j, i, old_index->hash_mask, hmask);
623
604
assert(j == i || j + old_index->hash_mask + 1 == i);
624
605
if ((entry->val & hmask) == i) {
625
606
/* Any entries not picked up here will be picked up on the
856
837
if (old_entry->ptr != NULL
857
838
|| old_entry >= old_index->hash[hash_offset + 1]) {
859
get_text(buff, entry->ptr);
860
fprintf(stderr, "Failed to find an opening @%x for %8x:\n '%s'\n",
861
hash_offset, entry->val, buff);
862
for (old_entry = old_index->hash[hash_offset];
863
old_entry < old_index->hash[hash_offset+1];
865
get_text(buff, old_entry->ptr);
866
fprintf(stderr, " [%2d] %8x %8x: '%s'\n",
867
(int)(old_entry - old_index->hash[hash_offset]),
868
old_entry->val, old_entry->ptr, buff);
839
/* There is no room for this entry, we have to resize */
841
// get_text(buff, entry->ptr);
842
// fprintf(stderr, "Failed to find an opening @%x for %8x:\n '%s'\n",
843
// hash_offset, entry->val, buff);
844
// for (old_entry = old_index->hash[hash_offset];
845
// old_entry < old_index->hash[hash_offset+1];
847
// get_text(buff, old_entry->ptr);
848
// fprintf(stderr, " [%2d] %8x %8x: '%s'\n",
849
// (int)(old_entry - old_index->hash[hash_offset]),
850
// old_entry->val, old_entry->ptr, buff);
880
862
/* We couldn't fit the new entries into the old index, so allocate a
881
863
* new one, and fill it with stuff.
883
fprintf(stderr, "inserted %d before resize\n", num_inserted);
865
// fprintf(stderr, "inserted %d before resize\n", num_inserted);
884
866
new_index = create_index_from_old_and_new_entries(old_index,
885
867
entry, num_entries);