~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/Rope.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 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
#ifndef NDB_ROPE_HPP
 
17
#define NDB_ROPE_HPP
 
18
 
 
19
#include "DataBuffer.hpp"
 
20
 
 
21
typedef DataBuffer<7> RopeBase;
 
22
typedef DataBuffer<7>::DataBufferPool RopePool;
 
23
 
 
24
struct RopeHandle {
 
25
  RopeHandle() { m_hash = 0; }
 
26
 
 
27
  Uint32 m_hash;
 
28
  RopeBase::Head m_head; 
 
29
 
 
30
  Uint32 hashValue() const { return m_hash; }
 
31
};
 
32
 
 
33
class ConstRope : private RopeBase {
 
34
public:
 
35
  ConstRope(RopePool& thePool, const RopeHandle& handle)  
 
36
    : RopeBase(thePool), src(handle)
 
37
  {
 
38
    this->head = src.m_head;
 
39
  }
 
40
  
 
41
  ~ConstRope(){
 
42
  }
 
43
 
 
44
  size_t size() const;
 
45
  bool empty() const;
 
46
 
 
47
  void copy(char* buf) const;
 
48
  
 
49
  int compare(const char * s) const { return compare(s, strlen(s) + 1); }
 
50
  int compare(const char *, size_t len) const; 
 
51
  
 
52
private:
 
53
  const RopeHandle & src;
 
54
};
 
55
 
 
56
class Rope : private RopeBase {
 
57
public:
 
58
  Rope(RopePool& thePool, RopeHandle& handle)  
 
59
    : RopeBase(thePool), src(handle)
 
60
  {
 
61
    this->head = src.m_head;
 
62
    m_hash = src.m_hash;
 
63
  }
 
64
  
 
65
  ~Rope(){
 
66
    src.m_head = this->head;
 
67
    src.m_hash = m_hash;
 
68
  }
 
69
 
 
70
  size_t size() const;
 
71
  bool empty() const;
 
72
 
 
73
  void copy(char* buf) const;
 
74
  
 
75
  int compare(const char * s) const { return compare(s, strlen(s) + 1); }
 
76
  int compare(const char *, size_t len) const; 
 
77
  
 
78
  bool assign(const char * s) { return assign(s, strlen(s) + 1);}
 
79
  bool assign(const char * s, size_t l) { return assign(s, l, hash(s, l));}
 
80
  bool assign(const char *, size_t len, Uint32 hash);
 
81
 
 
82
  void erase();
 
83
  
 
84
  static Uint32 hash(const char * str, Uint32 len);
 
85
 
 
86
private:
 
87
  Uint32 m_hash;
 
88
  RopeHandle & src;
 
89
};
 
90
 
 
91
inline
 
92
size_t
 
93
Rope::size() const {
 
94
  return head.used;
 
95
}
 
96
 
 
97
inline
 
98
bool
 
99
Rope::empty() const {
 
100
  return head.used == 0;
 
101
}
 
102
 
 
103
inline
 
104
size_t
 
105
ConstRope::size() const {
 
106
  return head.used;
 
107
}
 
108
 
 
109
inline
 
110
bool
 
111
ConstRope::empty() const {
 
112
  return head.used == 0;
 
113
}
 
114
 
 
115
#endif
 
116