LibreOffice Module store (master) 1
stortree.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <memory>
25
26#include <sal/types.h>
27
28#include <store/types.h>
29
30#include "storbase.hxx"
31
32namespace store
33{
34
35class OStorePageBIOS;
36
38{
41
44 sal_uInt32 m_nAttrib;
45
47 K const & rKey = K(),
48 L const & rLink = L())
49 : m_aKey (rKey),
50 m_aLink (rLink),
52 {}
53
55 {
59 };
60
62 {
63 if (m_aKey < rOther.m_aKey)
64 return COMPARE_LESS;
65 else if (m_aKey == rOther.m_aKey)
66 return COMPARE_EQUAL;
67 else
68 return COMPARE_GREATER;
69 }
70};
71
72#define STORE_MAGIC_BTREENODE sal_uInt32(0x58190322)
73
75{
76 typedef PageData base;
78
81
84
85 static const sal_uInt32 theTypeId = STORE_MAGIC_BTREENODE;
86
87 static const size_t theSize = sizeof(G);
88 static const sal_uInt16 thePageSize = base::theSize + self::theSize;
89 static_assert(STORE_MINIMUM_PAGESIZE >= self::thePageSize, "got to be at least equal in size");
90
91 sal_uInt16 capacity() const
92 {
93 return static_cast<sal_uInt16>(store::ntohs(base::m_aDescr.m_nSize) - self::thePageSize);
94 }
95
98 sal_uInt16 capacityCount() const
99 {
100 return sal_uInt16(capacity() / sizeof(T));
101 }
102
103 sal_uInt16 usage() const
104 {
105 return static_cast<sal_uInt16>(store::ntohs(base::m_aDescr.m_nUsed) - self::thePageSize);
106 }
107
108 sal_uInt16 usageCount() const
109 {
110 return sal_uInt16(usage() / sizeof(T));
111 }
112 void usageCount (sal_uInt16 nCount)
113 {
114 size_t const nBytes = self::thePageSize + nCount * sizeof(T);
115 base::m_aDescr.m_nUsed = store::htons(sal::static_int_cast< sal_uInt16 >(nBytes));
116 }
117
118 explicit OStoreBTreeNodeData (sal_uInt16 nPageSize);
119
120 void guard()
121 {
122 sal_uInt32 nCRC32 = rtl_crc32 (0, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
123 nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
125 }
126
128 {
129 sal_uInt32 nCRC32 = rtl_crc32 (0, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
130 nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
131 if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
133 else
134 return store_E_None;
135 }
136
137 sal_uInt32 depth() const
138 {
139 return store::ntohl(self::m_aGuard.m_nMagic);
140 }
141 void depth (sal_uInt32 nDepth)
142 {
144 }
145
146 bool querySplit() const
147 {
148 return usageCount() >= capacityCount();
149 }
150
151 sal_uInt16 find (const T& t) const;
152 void insert (sal_uInt16 i, const T& t);
153 void remove (sal_uInt16 i);
154
157 void split (const self& rPageL);
158
161 void truncate (sal_uInt16 n);
162};
163
165{
169
171
172public:
173 explicit OStoreBTreeNodeObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>())
174 : OStorePageObject (rxPage)
175 {}
176
177 virtual storeError guard (sal_uInt32 nAddr) override;
178 virtual storeError verify (sal_uInt32 nAddr) const override;
179
185 sal_uInt16 nIndexL,
186 PageHolderObject< page > & rxPageL,
187 OStorePageBIOS & rBIOS);
188
192 sal_uInt16 nIndexL,
193 OStoreBTreeEntry & rEntryL,
194 OStorePageBIOS & rBIOS);
195};
196
198{
201
203
204public:
205 explicit OStoreBTreeRootObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>())
206 : OStoreBTreeNodeObject (rxPage)
207 {}
208
210 sal_uInt32 nAddr,
211 OStorePageBIOS & rBIOS);
212
217 OStoreBTreeNodeObject & rNode, // [out]
218 sal_uInt16 & rIndex, // [out]
219 OStorePageKey const & rKey,
220 OStorePageBIOS & rBIOS) const;
221
226 OStoreBTreeNodeObject & rNode,
227 sal_uInt16 & rIndex,
228 OStorePageKey const & rKey,
229 OStorePageBIOS & rBIOS);
230
231private:
235 void testInvariant (char const * message) const;
236
242 PageHolderObject< page > & rxPageL,
243 OStorePageBIOS & rBIOS);
244};
245
246} // namespace store
247
248/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OStoreBTreeNodeObject self
Definition: stortree.hxx:167
virtual storeError guard(sal_uInt32 nAddr) override
Definition: stortree.cxx:131
storeError split(sal_uInt16 nIndexL, PageHolderObject< page > &rxPageL, OStorePageBIOS &rBIOS)
split.
Definition: stortree.cxx:141
OStoreBTreeNodeObject(std::shared_ptr< PageData > const &rxPage=std::shared_ptr< PageData >())
Definition: stortree.hxx:173
OStoreBTreeNodeData page
Definition: stortree.hxx:168
virtual storeError verify(sal_uInt32 nAddr) const override
Definition: stortree.cxx:136
storeError remove(sal_uInt16 nIndexL, OStoreBTreeEntry &rEntryL, OStorePageBIOS &rBIOS)
remove (down to leaf node, recursive).
Definition: stortree.cxx:191
OStoreBTreeNodeData page
Definition: stortree.hxx:200
storeError loadOrCreate(sal_uInt32 nAddr, OStorePageBIOS &rBIOS)
Definition: stortree.cxx:275
storeError find_lookup(OStoreBTreeNodeObject &rNode, sal_uInt16 &rIndex, OStorePageKey const &rKey, OStorePageBIOS &rBIOS) const
find_lookup (w/o split()).
Definition: stortree.cxx:338
storeError change(PageHolderObject< page > &rxPageL, OStorePageBIOS &rBIOS)
change (Root).
Definition: stortree.cxx:296
storeError find_insert(OStoreBTreeNodeObject &rNode, sal_uInt16 &rIndex, OStorePageKey const &rKey, OStorePageBIOS &rBIOS)
find_insert (possibly with split()).
Definition: stortree.cxx:405
OStoreBTreeNodeObject base
Definition: stortree.hxx:199
OStoreBTreeRootObject(std::shared_ptr< PageData > const &rxPage=std::shared_ptr< PageData >())
Definition: stortree.hxx:205
void testInvariant(char const *message) const
testInvariant.
Definition: stortree.cxx:269
int nCount
sal_uInt32 m_nSize
Definition: lockbyte.cxx:275
Old OStorePageCache implementation.
Definition: lockbyte.cxx:133
sal_uInt32 htonl(sal_uInt32 h)
Definition: storbase.hxx:69
sal_uInt16 ntohs(sal_uInt16 n)
Definition: storbase.hxx:67
sal_uInt32 ntohl(sal_uInt32 n)
Definition: storbase.hxx:70
sal_uInt16 htons(sal_uInt16 h)
Definition: storbase.hxx:66
#define STORE_MAGIC_BTREENODE
Definition: stortree.hxx:72
OStoreBTreeEntry(K const &rKey=K(), L const &rLink=L())
Definition: stortree.hxx:46
CompareResult compare(const OStoreBTreeEntry &rOther) const
Definition: stortree.hxx:61
OStorePageLink L
Definition: stortree.hxx:40
void split(const self &rPageL)
split (left half copied from right half of left page).
Definition: stortree.cxx:114
static const sal_uInt32 theTypeId
Definition: stortree.hxx:85
void remove(sal_uInt16 i)
Definition: stortree.cxx:97
sal_uInt16 capacityCount() const
capacityCount (must be even).
Definition: stortree.hxx:98
void truncate(sal_uInt16 n)
truncate (to n elements).
Definition: stortree.cxx:121
sal_uInt16 capacity() const
Definition: stortree.hxx:91
void usageCount(sal_uInt16 nCount)
Definition: stortree.hxx:112
static const sal_uInt16 thePageSize
Definition: stortree.hxx:88
storeError verify() const
Definition: stortree.hxx:127
void insert(sal_uInt16 i, const T &t)
Definition: stortree.cxx:82
void depth(sal_uInt32 nDepth)
Definition: stortree.hxx:141
OStoreBTreeNodeData self
Definition: stortree.hxx:77
static const size_t theSize
Definition: stortree.hxx:87
OStoreBTreeNodeData(sal_uInt16 nPageSize)
Definition: stortree.cxx:38
sal_uInt16 usageCount() const
Definition: stortree.hxx:108
sal_uInt16 find(const T &t) const
Definition: stortree.cxx:58
sal_uInt16 usage() const
Definition: stortree.hxx:103
OStoreBTreeEntry T
Definition: stortree.hxx:80
sal_uInt32 depth() const
Definition: stortree.hxx:137
sal_uInt32 m_nMagic
Representation.
Definition: storbase.hxx:77
static const size_t theSize
theSize.
Definition: storbase.hxx:250
constexpr sal_uInt16 STORE_MINIMUM_PAGESIZE
PageSize (enforced) limits.
Definition: types.h:37
storeError
Error Code enumeration.
Definition: types.h:73
@ store_E_None
Definition: types.h:74
@ store_E_InvalidChecksum
Definition: types.h:83