1
/* Copyright (C) 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 */
21
ConstRope::copy(char* buf) const {
24
ndbout_c("ConstRope::copy() head = [ %d 0x%x 0x%x ]",
25
head.used, head.firstItem, head.lastItem);
26
Uint32 left = head.used;
28
curr.i = head.firstItem;
29
while(left > 4 * getSegmentSize()){
31
memcpy(buf, curr.p->data, 4 * getSegmentSize());
32
curr.i = curr.p->nextPool;
33
left -= 4 * getSegmentSize();
34
buf += 4 * getSegmentSize();
38
memcpy(buf, curr.p->data, left);
42
ndbout_c("ConstRope::copy()-> %s", ptr);
46
ConstRope::compare(const char * str, size_t len) const {
48
ndbout_c("ConstRope[ %d 0x%x 0x%x ]::compare(%s, %d)",
49
head.used, head.firstItem, head.lastItem, str, (int) len);
50
Uint32 left = head.used > len ? len : head.used;
52
curr.i = head.firstItem;
53
while(left > 4 * getSegmentSize()){
55
int res = memcmp(str, (const char*)curr.p->data, 4 * getSegmentSize());
58
ndbout_c("ConstRope::compare(%s, %d, %s) -> %d", str, left,
59
(const char*)curr.p->data, res);
62
curr.i = curr.p->nextPool;
63
left -= 4 * getSegmentSize();
64
str += 4 * getSegmentSize();
69
int res = memcmp(str, (const char*)curr.p->data, left);
72
ndbout_c("ConstRope::compare(%s, %d, %s) -> %d",
73
str, left, (const char*)curr.p->data, res);
78
ndbout_c("ConstRope::compare(%s, %d) -> %d", str, (int) len, head.used > len);
79
return head.used > len;
83
Rope::copy(char* buf) const {
86
ndbout_c("Rope::copy() head = [ %d 0x%x 0x%x ]",
87
head.used, head.firstItem, head.lastItem);
88
Uint32 left = head.used;
90
curr.i = head.firstItem;
91
while(left > 4 * getSegmentSize()){
93
memcpy(buf, curr.p->data, 4 * getSegmentSize());
94
curr.i = curr.p->nextPool;
95
left -= 4 * getSegmentSize();
96
buf += 4 * getSegmentSize();
100
memcpy(buf, curr.p->data, left);
103
ndbout_c("Rope::copy()-> %s", ptr);
107
Rope::compare(const char * str, size_t len) const {
109
ndbout_c("Rope::compare(%s, %d)", str, (int) len);
110
Uint32 left = head.used > len ? len : head.used;
112
curr.i = head.firstItem;
113
while(left > 4 * getSegmentSize()){
114
thePool.getPtr(curr);
115
int res = memcmp(str, (const char*)curr.p->data, 4 * getSegmentSize());
118
ndbout_c("Rope::compare(%s, %d, %s) -> %d", str, (int) len,
119
(const char*)curr.p->data, res);
123
curr.i = curr.p->nextPool;
124
left -= 4 * getSegmentSize();
125
str += 4 * getSegmentSize();
129
thePool.getPtr(curr);
130
int res = memcmp(str, (const char*)curr.p->data, left);
133
ndbout_c("Rope::compare(%s, %d) -> %d", str, (int) len, res);
138
ndbout_c("Rope::compare(%s, %d) -> %d", str, (int) len, head.used > len);
139
return head.used > len;
143
Rope::assign(const char * s, size_t len, Uint32 hash){
145
ndbout_c("Rope::assign(%s, %d, 0x%x)", s, (int) len, hash);
147
head.used = (head.used + 3) / 4;
149
if(append((const Uint32*)s, len >> 2)){
152
const char * src = (const char*)(((Uint32*)s)+(len >> 2));
153
char* dst = (char*)&buf;
154
size_t left = len & 3;
164
ndbout_c("Rope::assign(...) head = [ %d 0x%x 0x%x ]",
165
head.used, head.firstItem, head.lastItem);
173
head.used = (head.used + 3) / 4;
178
Rope::hash(const char * p, Uint32 len){
180
ndbout_c("Rope::hash(%s, %d)", p, len);
182
for (; len > 0; len--)
183
h = (h << 5) + h + (* p++);
185
ndbout_c("Rope::hash(...) -> 0x%x", h);