~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_block.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
  {p_0, p_1, ...} serve as indexes to descend the blocks tree.
27
27
*/
28
28
 
29
 
unsigned char *hp_find_block(HP_BLOCK *block, uint32_t pos)
 
29
uchar *hp_find_block(HP_BLOCK *block, uint32_t pos)
30
30
{
31
31
  register int i;
32
32
  register HP_PTRS *ptr; /* block base ptr */
36
36
    ptr=(HP_PTRS*)ptr->blocks[pos/block->level_info[i].records_under_level];
37
37
    pos%=block->level_info[i].records_under_level;
38
38
  }
39
 
  return (unsigned char*) ptr+ pos*block->recbuffer;
 
39
  return (uchar*) ptr+ pos*block->recbuffer;
40
40
}
41
41
 
42
42
 
56
56
 
57
57
int hp_get_new_block(HP_BLOCK *block, size_t *alloc_length)
58
58
{
59
 
  register uint32_t i,j;
 
59
  register uint i,j;
60
60
  HP_PTRS *root;
61
61
 
62
62
  for (i=0 ; i < block->levels ; i++)
101
101
    /* Occupy the free slot we've found at level i */
102
102
    block->level_info[i].last_blocks->
103
103
      blocks[HP_PTRS_IN_NOD - block->level_info[i].free_ptrs_in_block--]=
104
 
        (unsigned char*) root;
 
104
        (uchar*) root;
105
105
    
106
106
    /* Add a block subtree with each node having one left-most child */
107
107
    for (j=i-1 ; j >0 ; j--)
108
108
    {
109
109
      block->level_info[j].last_blocks= root++;
110
 
      block->level_info[j].last_blocks->blocks[0]=(unsigned char*) root;
 
110
      block->level_info[j].last_blocks->blocks[0]=(uchar*) root;
111
111
      block->level_info[j].free_ptrs_in_block=HP_PTRS_IN_NOD-1;
112
112
    }
113
113
    
123
123
 
124
124
        /* free all blocks under level */
125
125
 
126
 
unsigned char *hp_free_level(HP_BLOCK *block, uint32_t level, HP_PTRS *pos, unsigned char *last_pos)
 
126
uchar *hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos, uchar *last_pos)
127
127
{
128
128
  int i,max_pos;
129
 
  unsigned char *next_ptr;
 
129
  uchar *next_ptr;
130
130
 
131
131
  if (level == 1)
132
 
    next_ptr=(unsigned char*) pos+block->recbuffer;
 
132
    next_ptr=(uchar*) pos+block->recbuffer;
133
133
  else
134
134
  {
135
135
    max_pos= (block->level_info[level-1].last_blocks == pos) ?
136
136
      HP_PTRS_IN_NOD - block->level_info[level-1].free_ptrs_in_block :
137
137
    HP_PTRS_IN_NOD;
138
138
 
139
 
    next_ptr=(unsigned char*) (pos+1);
 
139
    next_ptr=(uchar*) (pos+1);
140
140
    for (i=0 ; i < max_pos ; i++)
141
141
      next_ptr=hp_free_level(block,level-1,
142
142
                              (HP_PTRS*) pos->blocks[i],next_ptr);
143
143
  }
144
 
  if ((unsigned char*) pos != last_pos)
 
144
  if ((uchar*) pos != last_pos)
145
145
  {
146
 
    free((unsigned char*) pos);
 
146
    my_free((uchar*) pos,MYF(0));
147
147
    return last_pos;
148
148
  }
149
149
  return next_ptr;                      /* next memory position */