1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2011-2016 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#pragma once
20
21#include "dat.hpp"
22
23namespace grn {
24namespace dat {
25
26// The most significant bit represents whether or not the entry is valid.
27// A valid entry stores the position of its associated key and an invalid entry
28// stores the index of the next invalid entry.
29class GRN_DAT_API Entry {
30 public:
31 Entry() : value_(0) {}
32
33 bool is_valid() const {
34 return (value_ & IS_VALID_FLAG) == IS_VALID_FLAG;
35 }
36 UInt32 key_pos() const {
37 GRN_DAT_DEBUG_THROW_IF(!is_valid());
38 return value_ & ~IS_VALID_FLAG;
39 }
40 UInt32 next() const {
41 GRN_DAT_DEBUG_THROW_IF(is_valid());
42 return value_;
43 }
44
45 void set_key_pos(UInt32 x) {
46 value_ = IS_VALID_FLAG | x;
47 }
48 void set_next(UInt32 x) {
49 value_ = x;
50 }
51
52 private:
53 UInt32 value_;
54
55 static const UInt32 IS_VALID_FLAG = 0x80000000U;
56};
57
58} // namespace dat
59} // namespace grn
60