1
/* Copyright (C) 2000-2002, 2004, 2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
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 */
16
/* Read a record from a random position */
18
#include "heap_priv.h"
21
Returns one of following values:
23
HA_ERR_RECORD_DELETED = Record is deleted.
24
HA_ERR_END_OF_FILE = EOF.
27
int heap_rrnd(register HP_INFO *info, unsigned char *record, unsigned char *pos)
29
HP_SHARE *share=info->getShare();
32
if (!(info->current_ptr= pos))
35
return(errno= HA_ERR_END_OF_FILE);
37
if (get_chunk_status(&share->recordspace, info->current_ptr) != CHUNK_STATUS_ACTIVE)
39
/* treat deleted and linked chunks as deleted */
40
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
41
return(errno=HA_ERR_RECORD_DELETED);
43
info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
44
hp_extract_record(share, record, info->current_ptr);
45
info->current_hash_ptr=0; /* Can't use rnext */
50
#ifdef WANT_OLD_HEAP_VERSION
53
If pos == -1 then read next record
54
Returns one of following values:
56
HA_ERR_RECORD_DELETED = Record is deleted.
57
HA_ERR_END_OF_FILE = EOF.
60
int heap_rrnd_old(register HP_INFO *info, unsigned char *record, uint32_t pos)
62
HP_SHARE *share=info->s;
65
if (pos == (uint32_t) -1)
67
pos= ++info->current_record;
68
if (pos % share->block.records_in_block && /* Quick next record */
69
pos < share->used_chunk_count+share->deleted_chunk_count &&
70
(info->update & HA_STATE_PREV_FOUND))
72
info->current_ptr+=share->block.recbufferlen;
77
info->current_record=pos;
79
if (pos >= share->used_chunk_count+share->deleted_chunk_count)
82
return(errno= HA_ERR_END_OF_FILE);
85
/* Find record number pos */
86
hp_find_record(info, pos);
89
if (!info->current_ptr[share->reclength])
91
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
92
return(errno=HA_ERR_RECORD_DELETED);
94
info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
95
memcpy(record,info->current_ptr,(size_t) share->reclength);
96
info->current_hash_ptr=0; /* Can't use rnext */
100
#endif /* WANT_OLD_HEAP_VERSION */