MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rope.hpp
1 /*
2  Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NDB_ROPE_HPP
19 #define NDB_ROPE_HPP
20 
21 #include "DataBuffer.hpp"
22 
23 typedef DataBuffer<7> RopeBase;
24 typedef DataBuffer<7>::DataBufferPool RopePool;
25 
26 struct RopeHandle {
27  RopeHandle() { m_hash = 0; }
28 
29  Uint32 m_hash;
30  RopeBase::Head m_head;
31 
32  Uint32 hashValue() const { return m_hash; }
33 };
34 
35 class ConstRope : private RopeBase {
36 public:
37  ConstRope(RopePool& thePool, const RopeHandle& handle)
38  : RopeBase(thePool), src(handle)
39  {
40  this->head = src.m_head;
41  }
42 
43  ~ConstRope(){
44  }
45 
46  Uint32 size() const;
47  bool empty() const;
48 
49  void copy(char* buf) const;
50 
51  int compare(const char * s) const { return compare(s, (Uint32)strlen(s) + 1);}
52  int compare(const char *, Uint32 len) const;
53 
54  bool equal(const ConstRope& r2) const;
55 private:
56  const RopeHandle & src;
57 };
58 
59 class Rope : private RopeBase {
60 public:
61  Rope(RopePool& thePool, RopeHandle& handle)
62  : RopeBase(thePool), src(handle)
63  {
64  this->head = src.m_head;
65  m_hash = src.m_hash;
66  }
67 
68  ~Rope(){
69  src.m_head = this->head;
70  src.m_hash = m_hash;
71  }
72 
73  Uint32 size() const;
74  bool empty() const;
75 
76  void copy(char* buf) const;
77 
78  int compare(const char * s) const { return compare(s, Uint32(strlen(s) + 1));}
79  int compare(const char *, Uint32 len) const;
80 
81  bool assign(const char * s) { return assign(s, Uint32(strlen(s) + 1));}
82  bool assign(const char * s, Uint32 l) { return assign(s, l, hash(s, l));}
83  bool assign(const char *, Uint32 len, Uint32 hash);
84 
85  void erase();
86 
87  static Uint32 hash(const char * str, Uint32 len);
88 
89  static Uint32 getSegmentSize() { return RopeBase::getSegmentSize();}
90 private:
91  Uint32 m_hash;
92  RopeHandle & src;
93 };
94 
95 inline
96 Uint32
97 Rope::size() const {
98  return head.used;
99 }
100 
101 inline
102 bool
103 Rope::empty() const {
104  return head.used == 0;
105 }
106 
107 inline
108 Uint32
109 ConstRope::size() const {
110  return head.used;
111 }
112 
113 inline
114 bool
115 ConstRope::empty() const {
116  return head.used == 0;
117 }
118 
119 #endif
120