~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_block.c

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* functions on blocks; Keys and records are saved in blocks */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
#include <cstdlib>
 
18
#include "heapdef.h"
21
19
 
22
20
/*
23
21
  Find record according to record-position.
30
28
 
31
29
unsigned char *hp_find_block(HP_BLOCK *block, uint32_t pos)
32
30
{
33
 
  int i;
34
 
  HP_PTRS *ptr; /* block base ptr */
 
31
  register int i;
 
32
  register HP_PTRS *ptr; /* block base ptr */
35
33
 
36
 
  for (i= block->levels-1, ptr=block->root ; i > 0 ; i--)
 
34
  for (i=block->levels-1, ptr=block->root ; i > 0 ; i--)
37
35
  {
38
36
    ptr=(HP_PTRS*)ptr->blocks[pos/block->level_info[i].records_under_level];
39
37
    pos%=block->level_info[i].records_under_level;
58
56
 
59
57
int hp_get_new_block(HP_BLOCK *block, size_t *alloc_length)
60
58
{
61
 
  uint32_t i;
 
59
  register uint32_t i,j;
62
60
  HP_PTRS *root;
63
61
 
64
62
  for (i=0 ; i < block->levels ; i++)
106
104
        (unsigned char*) root;
107
105
 
108
106
    /* Add a block subtree with each node having one left-most child */
109
 
    for (uint32_t j= i-1 ; j >0 ; j--)
 
107
    for (j=i-1 ; j >0 ; j--)
110
108
    {
111
109
      block->level_info[j].last_blocks= root++;
112
110
      block->level_info[j].last_blocks->blocks[0]=(unsigned char*) root;
127
125
 
128
126
unsigned char *hp_free_level(HP_BLOCK *block, uint32_t level, HP_PTRS *pos, unsigned char *last_pos)
129
127
{
130
 
  int max_pos;
 
128
  int i,max_pos;
131
129
  unsigned char *next_ptr;
132
130
 
133
131
  if (level == 1)
134
 
  {
135
132
    next_ptr=(unsigned char*) pos+block->recbuffer;
136
 
  }
137
133
  else
138
134
  {
139
135
    max_pos= (block->level_info[level-1].last_blocks == pos) ?
141
137
    HP_PTRS_IN_NOD;
142
138
 
143
139
    next_ptr=(unsigned char*) (pos+1);
144
 
    for (int i= 0; i < max_pos ; i++)
 
140
    for (i=0 ; i < max_pos ; i++)
145
141
      next_ptr=hp_free_level(block,level-1,
146
142
                              (HP_PTRS*) pos->blocks[i],next_ptr);
147
143
  }
148
 
 
149
144
  if ((unsigned char*) pos != last_pos)
150
145
  {
151
146
    free((unsigned char*) pos);