19 #include "DataBuffer2.hpp"
24 ConstRope::copy(
char*
buf)
const {
27 ndbout_c(
"ConstRope::copy() head = [ %d 0x%x 0x%x ]",
28 head.used, head.firstItem, head.lastItem);
29 Uint32 left = head.used;
31 curr.i = head.firstItem;
35 curr.i = curr.p->nextPool;
41 memcpy(buf, curr.p->data, left);
45 ndbout_c(
"ConstRope::copy()-> %s", ptr);
49 ConstRope::compare(
const char * str, Uint32 len)
const {
51 ndbout_c(
"ConstRope[ %d 0x%x 0x%x ]::compare(%s, %d)",
52 head.used, head.firstItem, head.lastItem, str, (
int) len);
53 Uint32 left = head.used > len ? len : head.used;
55 curr.i = head.firstItem;
58 int res = memcmp(str, (
const char*)curr.p->data, 4 *
getSegmentSize());
61 ndbout_c(
"ConstRope::compare(%s, %d, %s) -> %d", str, left,
62 (
const char*)curr.p->data, res);
65 curr.i = curr.p->nextPool;
72 int res = memcmp(str, (
const char*)curr.p->data, left);
75 ndbout_c(
"ConstRope::compare(%s, %d, %s) -> %d",
76 str, left, (
const char*)curr.p->data, res);
81 ndbout_c(
"ConstRope::compare(%s, %d) -> %d", str, (
int) len, head.used > len);
82 return head.used > len;
86 Rope::copy(
char* buf)
const {
89 ndbout_c(
"Rope::copy() head = [ %d 0x%x 0x%x ]",
90 head.used, head.firstItem, head.lastItem);
91 Uint32 left = head.used;
93 curr.i = head.firstItem;
94 while(left > 4 * getSegmentSize()){
96 memcpy(buf, curr.p->data, 4 * getSegmentSize());
97 curr.i = curr.p->nextPool;
98 left -= 4 * getSegmentSize();
99 buf += 4 * getSegmentSize();
103 memcpy(buf, curr.p->data, left);
106 ndbout_c(
"Rope::copy()-> %s", ptr);
110 Rope::compare(
const char * str, Uint32 len)
const {
112 ndbout_c(
"Rope::compare(%s, %d)", str, (
int) len);
113 Uint32 left = head.used > len ? len : head.used;
115 curr.i = head.firstItem;
116 while(left > 4 * getSegmentSize()){
118 int res = memcmp(str, (
const char*)curr.p->data, 4 * getSegmentSize());
121 ndbout_c(
"Rope::compare(%s, %d, %s) -> %d", str, (
int) len,
122 (
const char*)curr.p->data, res);
126 curr.i = curr.p->nextPool;
127 left -= 4 * getSegmentSize();
128 str += 4 * getSegmentSize();
133 int res = memcmp(str, (
const char*)curr.p->data, left);
136 ndbout_c(
"Rope::compare(%s, %d) -> %d", str, (
int) len, res);
141 ndbout_c(
"Rope::compare(%s, %d) -> %d", str, (
int) len, head.used > len);
142 return head.used > len;
146 Rope::assign(
const char * s, Uint32 len, Uint32 hash){
148 ndbout_c(
"Rope::assign(%s, %d, 0x%x)", s, (
int) len, hash);
150 head.used = (head.used + 3) / 4;
152 if(
append((
const Uint32*)s, len >> 2)){
155 const char * src = (
const char*)(((Uint32*)s)+(len >> 2));
156 char* dst = (
char*)&buf;
157 Uint32 left = len & 3;
167 ndbout_c(
"Rope::assign(...) head = [ %d 0x%x 0x%x ]",
168 head.used, head.firstItem, head.lastItem);
176 head.used = (head.used + 3) / 4;
181 Rope::hash(
const char * p, Uint32 len){
183 ndbout_c(
"Rope::hash(%s, %d)", p, len);
185 for (; len > 0; len--)
186 h = (h << 5) + h + (* p++);
188 ndbout_c(
"Rope::hash(...) -> 0x%x", h);
193 ConstRope::equal(
const ConstRope& r2)
const
195 if (head.used != r2.head.used)
198 if (src.m_hash != r2.src.m_hash)
201 Uint32 left = head.used;
203 s1.i = head.firstItem;
204 s2.i = r2.head.firstItem;
214 s1.i = s1.p->nextPool;
215 s2.i = s2.p->nextPool;
223 int res = memcmp(s1.p->data, s2.p->data, left);