libfoedus-core
FOEDUS Core Library
array_id.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_STORAGE_ARRAY_ARRAY_ID_HPP_
19 #define FOEDUS_STORAGE_ARRAY_ARRAY_ID_HPP_
20 #include <stdint.h>
21 
22 #include <iosfwd>
23 
25 
31 namespace foedus {
32 namespace storage {
33 namespace array {
34 
48 typedef uint64_t ArrayOffset;
49 
54 const ArrayOffset kMaxArrayOffset = (1ULL << 48) - 1ULL;
55 
62 struct ArrayRange {
63  ArrayRange() : begin_(0), end_(0) {}
64  ArrayRange(ArrayOffset begin, ArrayOffset end) : begin_(begin), end_(end) {}
66  ArrayRange(ArrayOffset begin, ArrayOffset end, ArrayOffset array_size)
67  : begin_(begin), end_(end) {
68  if (end > array_size) {
69  end_ = array_size;
70  }
71  }
72 
74  bool overlaps(const ArrayRange& other) const {
75  // Case 1: contains(other.begin) or contains(other.end)
76  // Case 2: not case 1, but other.contains(begin)
77  return contains(other.begin_) || contains(other.end_) || other.contains(begin_);
78  }
79  bool contains(ArrayOffset offset) const { return offset >= begin_ && offset < end_; }
80  bool operator==(const ArrayRange& other) const {
81  return begin_ == other.begin_ && end_ == other.end_;
82  }
83  bool operator!=(const ArrayRange& other) const { return !(this->operator==(other)); }
84 
86  ArrayOffset begin_;
88  ArrayOffset end_;
89 };
90 
95 const uint16_t kHeaderSize = 64;
105 const uint16_t kInteriorSize = 16;
110 const uint16_t kInteriorFanout = (foedus::storage::kPageSize - kHeaderSize) / kInteriorSize;
111 
118 const uint8_t kMaxLevels = 8;
119 
120 } // namespace array
121 } // namespace storage
122 } // namespace foedus
123 #endif // FOEDUS_STORAGE_ARRAY_ARRAY_ID_HPP_
bool operator!=(const ArrayRange &other) const
Definition: array_id.hpp:83
Definitions of IDs in this package and a few related constant values.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const ArrayOffset kMaxArrayOffset
The maximum value allowed for ArrayOffset.
Definition: array_id.hpp:54
uint64_t ArrayOffset
The only key type in array storage.
Definition: array_id.hpp:48
const uint16_t kInteriorSize
Byte size of an entry in interior page of array storage.
Definition: array_id.hpp:105
const uint8_t kMaxLevels
Code in array storage assumes this number as the maximum number of levels.
Definition: array_id.hpp:118
ArrayRange(ArrayOffset begin, ArrayOffset end, ArrayOffset array_size)
this one adjusts the case where end might be larger than the whole array size (right-most) ...
Definition: array_id.hpp:66
const uint16_t kDataSize
Byte size of data region in each page of array storage.
Definition: array_id.hpp:100
ArrayOffset begin_
Inclusive beginning of the offset range.
Definition: array_id.hpp:86
ArrayOffset end_
Exclusive end of the offset range.
Definition: array_id.hpp:88
bool overlaps(const ArrayRange &other) const
Returns if there is any overlap with the other range.
Definition: array_id.hpp:74
bool contains(ArrayOffset offset) const
Definition: array_id.hpp:79
Represents an offset range in an array storage.
Definition: array_id.hpp:62
bool operator==(const ArrayRange &other) const
Definition: array_id.hpp:80
const uint16_t kHeaderSize
Byte size of header in each page of array storage.
Definition: array_id.hpp:95
const uint16_t kInteriorFanout
Max number of entries in an interior page of array storage.
Definition: array_id.hpp:110
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45
ArrayRange(ArrayOffset begin, ArrayOffset end)
Definition: array_id.hpp:64