18 #include "heap_priv.h"
19 #include <drizzled/error_t.h>
20 #include <drizzled/internal/my_sys.h>
22 int heap_delete(
HP_INFO *info,
const unsigned char *record)
30 if (info->opt_flag & READ_CHECK_USED)
34 if ( --(share->records) < share->blength >> 1) share->blength>>=1;
35 pos=info->current_ptr;
37 p_lastinx = share->keydef + info->lastinx;
38 for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
41 if (hp_delete_key(info, keydef, record, pos, keydef == p_lastinx))
45 info->update=HA_STATE_DELETED;
46 hp_free_chunks(&share->recordspace, pos);
47 info->current_hash_ptr=0;
51 if (++(share->records) == share->blength)
52 share->blength+= share->blength;
74 const unsigned char *record,
unsigned char *recpos,
int flag)
76 uint32_t blength,pos2,pos_hashnr,lastpos_hashnr;
77 HASH_INFO *lastpos,*gpos,*pos,*pos3,*empty,*last_ptr;
80 blength=share->blength;
81 if (share->records+1 == blength)
86 lastpos=hp_find_hash(&keyinfo->block,share->records);
90 pos= hp_find_hash(&keyinfo->block,
91 hp_mask(hp_rec_hashnr(keyinfo, record), blength,
95 while (pos->ptr_to_rec != recpos)
97 if (flag && !hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 0))
100 if (!(pos=pos->next_key))
102 return(errno= drizzled::HA_ERR_CRASHED);
111 info->current_hash_ptr=last_ptr;
112 info->current_ptr = last_ptr ? last_ptr->ptr_to_rec : 0;
117 gpos->next_key=pos->next_key;
119 else if (pos->next_key)
125 pos->ptr_to_rec=empty->ptr_to_rec;
126 pos->next_key=empty->next_key;
131 keyinfo->hash_buckets--;
134 if (empty == lastpos)
138 lastpos_hashnr = hp_rec_hashnr(keyinfo, lastpos->ptr_to_rec);
140 pos=hp_find_hash(&keyinfo->block, hp_mask(lastpos_hashnr, share->blength,
147 pos_hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
149 pos3= hp_find_hash(&keyinfo->block,
150 hp_mask(pos_hashnr, share->blength, share->records));
155 hp_movelink(pos, pos3, empty);
158 pos2= hp_mask(lastpos_hashnr, blength, share->records + 1);
159 if (pos2 == hp_mask(pos_hashnr, blength, share->records + 1))
161 if (pos2 != share->records)
164 hp_movelink(lastpos, pos, empty);
172 keyinfo->hash_buckets--;
176 hp_movelink(pos3, empty, pos->next_key);