Navigation Menu

Skip to content

Commit

Permalink
Move headers into subdirectories.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Jun 5, 2013
1 parent 10d9ce7 commit 52ca8d6
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 67 deletions.
30 changes: 7 additions & 23 deletions lib/grnxx/map/array_map.cpp
Expand Up @@ -22,29 +22,13 @@
#include "grnxx/bytes.hpp"
#include "grnxx/geo_point.hpp"
#include "grnxx/logger.hpp"
#include "grnxx/map/array_map/header.hpp"
#include "grnxx/map/helper.hpp"
#include "grnxx/storage.hpp"

namespace grnxx {
namespace map {

struct ArrayMapHeader {
MapType map_type;
uint32_t keys_storage_node_id;
uint32_t bits_storage_node_id;
int64_t max_key_id;
uint64_t num_keys;

ArrayMapHeader();
};

ArrayMapHeader::ArrayMapHeader()
: map_type(MAP_ARRAY),
keys_storage_node_id(STORAGE_INVALID_NODE_ID),
bits_storage_node_id(STORAGE_INVALID_NODE_ID),
max_key_id(MAP_MIN_KEY_ID - 1),
num_keys(0) {}

template <typename T>
ArrayMap<T>::ArrayMap()
: storage_(nullptr),
Expand Down Expand Up @@ -304,13 +288,13 @@ bool ArrayMap<T>::create_map(Storage *storage, uint32_t storage_node_id,
const MapOptions &) {
storage_ = storage;
StorageNode storage_node =
storage->create_node(storage_node_id, sizeof(ArrayMapHeader));
storage->create_node(storage_node_id, sizeof(Header));
if (!storage_node) {
return false;
}
storage_node_id_ = storage_node.id();
header_ = static_cast<ArrayMapHeader *>(storage_node.body());
*header_ = ArrayMapHeader();
header_ = static_cast<Header *>(storage_node.body());
*header_ = Header();
keys_.reset(KeyArray::create(storage, storage_node_id_));
bits_.reset(BitArray::create(storage, storage_node_id_));
if (!keys_ || !bits_) {
Expand All @@ -329,13 +313,13 @@ bool ArrayMap<T>::open_map(Storage *storage, uint32_t storage_node_id) {
if (!storage_node) {
return false;
}
if (storage_node.size() < sizeof(ArrayMapHeader)) {
if (storage_node.size() < sizeof(Header)) {
GRNXX_ERROR() << "invalid format: size = " << storage_node.size()
<< ", header_size = " << sizeof(ArrayMapHeader);
<< ", header_size = " << sizeof(Header);
return false;
}
storage_node_id_ = storage_node_id;
header_ = static_cast<ArrayMapHeader *>(storage_node.body());
header_ = static_cast<Header *>(storage_node.body());
keys_.reset(KeyArray::open(storage, header_->keys_storage_node_id));
bits_.reset(BitArray::open(storage, header_->bits_storage_node_id));
if (!keys_ || !bits_) {
Expand Down
8 changes: 6 additions & 2 deletions lib/grnxx/map/array_map.hpp
Expand Up @@ -32,11 +32,15 @@ namespace grnxx {
class Storage;

namespace map {
namespace array_map {

struct ArrayMapHeader;
struct Header;

} // namespace array_map

template <typename T>
class ArrayMap : public Map<T> {
using Header = array_map::Header;
using KeyArray = typename array_map::KeyArray<T>::Type;
using BitArray = typename array_map::BitArray<T>::Type;
using BitArrayUnit = typename BitArray::Unit;
Expand Down Expand Up @@ -73,7 +77,7 @@ class ArrayMap : public Map<T> {
private:
Storage *storage_;
uint32_t storage_node_id_;
ArrayMapHeader *header_;
Header *header_;
std::unique_ptr<KeyArray> keys_;
std::unique_ptr<BitArray> bits_;

Expand Down
4 changes: 3 additions & 1 deletion lib/grnxx/map/array_map/Makefile.am
Expand Up @@ -3,10 +3,12 @@ noinst_LTLIBRARIES = libgrnxx_map_array_map.la
libgrnxx_map_array_map_la_LDFLAGS = @AM_LTLDFLAGS@

libgrnxx_map_array_map_la_SOURCES = \
dummy.cpp
dummy.cpp \
header.cpp

libgrnxx_map_array_map_includedir = ${includedir}/grnxx/map/array_map
libgrnxx_map_array_map_include_HEADERS = \
bit_array.hpp \
dummy.hpp \
header.hpp \
key_array.hpp
1 change: 1 addition & 0 deletions lib/grnxx/map/array_map/dummy.cpp
Expand Up @@ -18,6 +18,7 @@
#include "grnxx/map/array_map/dummy.hpp"

#include "grnxx/map/array_map/bit_array.hpp"
#include "grnxx/map/array_map/header.hpp"
#include "grnxx/map/array_map/key_array.hpp"

namespace grnxx {
Expand Down
35 changes: 35 additions & 0 deletions lib/grnxx/map/array_map/header.cpp
@@ -0,0 +1,35 @@
/*
Copyright (C) 2012-2013 Brazil, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grnxx/map/array_map/header.hpp"

#include "grnxx/storage.hpp"

namespace grnxx {
namespace map {
namespace array_map {

Header::Header()
: map_type(MAP_ARRAY),
keys_storage_node_id(STORAGE_INVALID_NODE_ID),
bits_storage_node_id(STORAGE_INVALID_NODE_ID),
max_key_id(MAP_MIN_KEY_ID - 1),
num_keys(0) {}

} // namespace array_map
} // namespace map
} // namespace grnxx
44 changes: 44 additions & 0 deletions lib/grnxx/map/array_map/header.hpp
@@ -0,0 +1,44 @@
/*
Copyright (C) 2012-2013 Brazil, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRNXX_MAP_ARRAY_MAP_HEADER_HPP
#define GRNXX_MAP_ARRAY_MAP_HEADER_HPP

#include "grnxx/features.hpp"

#include "grnxx/map.hpp"
#include "grnxx/types.hpp"

namespace grnxx {
namespace map {
namespace array_map {

struct Header {
MapType map_type;
uint32_t keys_storage_node_id;
uint32_t bits_storage_node_id;
int64_t max_key_id;
uint64_t num_keys;

Header();
};

} // namespace array_map
} // namespace map
} // namespace grnxx

#endif // GRNXX_MAP_ARRAY_MAP_HEADER_HPP
45 changes: 8 additions & 37 deletions lib/grnxx/map/hash_table.cpp
Expand Up @@ -25,6 +25,7 @@
#include "grnxx/lock.hpp"
#include "grnxx/logger.hpp"
#include "grnxx/map/hash_table/hash.hpp"
#include "grnxx/map/hash_table/header.hpp"
#include "grnxx/map/helper.hpp"
#include "grnxx/mutex.hpp"
#include "grnxx/storage.hpp"
Expand All @@ -34,37 +35,7 @@ namespace map {

template <typename T>
using Hash = hash_table::Hash<T>;

constexpr uint64_t INVALID_LINK = uint64_t(-1);

struct HashTableHeader {
MapType map_type;
uint32_t key_ids_storage_node_id;
uint32_t old_key_ids_storage_node_id;
uint32_t keys_storage_node_id;
uint32_t bits_storage_node_id;
uint32_t links_storage_node_id;
int64_t max_key_id;
uint64_t num_keys;
uint64_t num_key_ids;
uint64_t latest_link;
Mutex mutex;

HashTableHeader();
};

HashTableHeader::HashTableHeader()
: map_type(MAP_HASH_TABLE),
key_ids_storage_node_id(STORAGE_INVALID_NODE_ID),
old_key_ids_storage_node_id(STORAGE_INVALID_NODE_ID),
keys_storage_node_id(STORAGE_INVALID_NODE_ID),
bits_storage_node_id(STORAGE_INVALID_NODE_ID),
links_storage_node_id(STORAGE_INVALID_NODE_ID),
max_key_id(MAP_MIN_KEY_ID - 1),
num_keys(0),
num_key_ids(0),
latest_link(INVALID_LINK),
mutex(MUTEX_UNLOCKED) {}
using hash_table::INVALID_LINK;

template <typename T>
HashTable<T>::HashTable()
Expand Down Expand Up @@ -425,13 +396,13 @@ bool HashTable<T>::create_map(Storage *storage, uint32_t storage_node_id,
const MapOptions &) {
storage_ = storage;
StorageNode storage_node =
storage->create_node(storage_node_id, sizeof(HashTableHeader));
storage->create_node(storage_node_id, sizeof(Header));
if (!storage_node) {
return false;
}
storage_node_id_ = storage_node.id();
header_ = static_cast<HashTableHeader *>(storage_node.body());
*header_ = HashTableHeader();
header_ = static_cast<Header *>(storage_node.body());
*header_ = Header();
key_ids_.reset(KeyIDArray::create(storage, storage_node_id_,
KeyIDArray::page_size() - 1));
keys_.reset(KeyArray::create(storage, storage_node_id_));
Expand All @@ -455,13 +426,13 @@ bool HashTable<T>::open_map(Storage *storage, uint32_t storage_node_id) {
if (!storage_node) {
return false;
}
if (storage_node.size() < sizeof(HashTableHeader)) {
if (storage_node.size() < sizeof(Header)) {
GRNXX_ERROR() << "invalid format: size = " << storage_node.size()
<< ", header_size = " << sizeof(HashTableHeader);
<< ", header_size = " << sizeof(Header);
return false;
}
storage_node_id_ = storage_node_id;
header_ = static_cast<HashTableHeader *>(storage_node.body());
header_ = static_cast<Header *>(storage_node.body());
key_ids_.reset(KeyIDArray::open(storage, header_->key_ids_storage_node_id));
keys_.reset(KeyArray::open(storage, header_->keys_storage_node_id));
bits_.reset(BitArray::open(storage, header_->bits_storage_node_id));
Expand Down
11 changes: 9 additions & 2 deletions lib/grnxx/map/hash_table.hpp
Expand Up @@ -30,12 +30,19 @@
#include "grnxx/types.hpp"

namespace grnxx {

class Storage;

namespace map {
namespace hash_table {

struct Header;

struct HashTableHeader;
} // namespace hash_table

template <typename T>
class HashTable : public Map<T> {
using Header = hash_table::Header;
using KeyIDArray = typename hash_table::KeyIDArray<T>;
using KeyArray = typename hash_table::KeyArray<T>::Type;
using BitArray = typename hash_table::BitArray<T>::Type;
Expand Down Expand Up @@ -74,7 +81,7 @@ class HashTable : public Map<T> {
private:
Storage *storage_;
uint32_t storage_node_id_;
HashTableHeader *header_;
Header *header_;
std::unique_ptr<KeyIDArray> key_ids_;
std::unique_ptr<KeyIDArray> old_key_ids_;
std::unique_ptr<KeyArray> keys_;
Expand Down
6 changes: 4 additions & 2 deletions lib/grnxx/map/hash_table/Makefile.am
Expand Up @@ -2,14 +2,16 @@ noinst_LTLIBRARIES = libgrnxx_map_hash_table.la

libgrnxx_map_hash_table_la_LDFLAGS = @AM_LTLDFLAGS@

libgrnxx_map_hash_table_la_SOURCES = \
dummy.cpp
libgrnxx_map_hash_table_la_SOURCES = \
dummy.cpp \
header.cpp

libgrnxx_map_hash_table_includedir = ${includedir}/grnxx/map/hash_table
libgrnxx_map_hash_table_include_HEADERS = \
bit_array.hpp \
dummy.hpp \
hash.hpp \
header.hpp \
key_array.hpp \
key_id_array.hpp \
link_array.hpp
42 changes: 42 additions & 0 deletions lib/grnxx/map/hash_table/header.cpp
@@ -0,0 +1,42 @@
/*
Copyright (C) 2012-2013 Brazil, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grnxx/map/hash_table/header.hpp"

#include "grnxx/map/hash_table/link_array.hpp"
#include "grnxx/storage.hpp"

namespace grnxx {
namespace map {
namespace hash_table {

Header::Header()
: map_type(MAP_HASH_TABLE),
key_ids_storage_node_id(STORAGE_INVALID_NODE_ID),
old_key_ids_storage_node_id(STORAGE_INVALID_NODE_ID),
keys_storage_node_id(STORAGE_INVALID_NODE_ID),
bits_storage_node_id(STORAGE_INVALID_NODE_ID),
links_storage_node_id(STORAGE_INVALID_NODE_ID),
max_key_id(MAP_MIN_KEY_ID - 1),
num_keys(0),
num_key_ids(0),
latest_link(INVALID_LINK),
mutex(MUTEX_UNLOCKED) {}

} // namespace hash_table
} // namespace map
} // namespace grnxx

0 comments on commit 52ca8d6

Please sign in to comment.