~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_rrnd.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2002, 2004, 2006 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* Read a record from a random position */
 
17
 
 
18
#include "heapdef.h"
 
19
 
 
20
/*
 
21
           Returns one of following values:
 
22
           0 = Ok.
 
23
           HA_ERR_RECORD_DELETED = Record is deleted.
 
24
           HA_ERR_END_OF_FILE = EOF.
 
25
*/
 
26
 
 
27
int heap_rrnd(register HP_INFO *info, uchar *record, uchar *pos)
 
28
{
 
29
  HP_SHARE *share=info->s;
 
30
  DBUG_ENTER("heap_rrnd");
 
31
  DBUG_PRINT("enter",("info: 0x%lx  pos: %lx",(long) info, (long) pos));
 
32
 
 
33
  info->lastinx= -1;
 
34
  if (!(info->current_ptr= pos))
 
35
  {
 
36
    info->update= 0;
 
37
    DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
 
38
  }
 
39
  if (!info->current_ptr[share->reclength])
 
40
  {
 
41
    info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
 
42
    DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
 
43
  }
 
44
  info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
 
45
  memcpy(record,info->current_ptr,(size_t) share->reclength);
 
46
  DBUG_PRINT("exit", ("found record at 0x%lx", (long) info->current_ptr));
 
47
  info->current_hash_ptr=0;                     /* Can't use rnext */
 
48
  DBUG_RETURN(0);
 
49
} /* heap_rrnd */
 
50
 
 
51
 
 
52
#ifdef WANT_OLD_HEAP_VERSION
 
53
 
 
54
/*
 
55
           If pos == -1 then read next record
 
56
           Returns one of following values:
 
57
           0 = Ok.
 
58
           HA_ERR_RECORD_DELETED = Record is deleted.
 
59
           HA_ERR_END_OF_FILE = EOF.
 
60
*/
 
61
 
 
62
int heap_rrnd_old(register HP_INFO *info, uchar *record, ulong pos)
 
63
{
 
64
  HP_SHARE *share=info->s;
 
65
  DBUG_ENTER("heap_rrnd");
 
66
  DBUG_PRINT("enter",("info: 0x%lx  pos: %ld",info,pos));
 
67
 
 
68
  info->lastinx= -1;
 
69
  if (pos == (ulong) -1)
 
70
  {
 
71
    pos= ++info->current_record;
 
72
    if (pos % share->block.records_in_block &&  /* Quick next record */
 
73
        pos < share->records+share->deleted &&
 
74
        (info->update & HA_STATE_PREV_FOUND))
 
75
    {
 
76
      info->current_ptr+=share->block.recbuffer;
 
77
      goto end;
 
78
    }
 
79
  }
 
80
  else
 
81
    info->current_record=pos;
 
82
 
 
83
  if (pos >= share->records+share->deleted)
 
84
  {
 
85
    info->update= 0;
 
86
    DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
 
87
  }
 
88
 
 
89
        /* Find record number pos */
 
90
  hp_find_record(info, pos);
 
91
 
 
92
end:
 
93
  if (!info->current_ptr[share->reclength])
 
94
  {
 
95
    info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
 
96
    DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
 
97
  }
 
98
  info->update=HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND | HA_STATE_AKTIV;
 
99
  memcpy(record,info->current_ptr,(size_t) share->reclength);
 
100
  DBUG_PRINT("exit",("found record at 0x%lx",info->current_ptr));
 
101
  info->current_hash_ptr=0;                     /* Can't use rnext */
 
102
  DBUG_RETURN(0);
 
103
} /* heap_rrnd */
 
104
 
 
105
#endif /* WANT_OLD_HEAP_VERSION */