Navigation Menu

Skip to content

Commit

Permalink
Update the implementation of grnxx::map::ArrayMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Jun 4, 2013
1 parent 6e20323 commit a31db52
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 64 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -66,6 +66,7 @@ AC_CONFIG_FILES([Makefile
lib/grnxx/db/Makefile
lib/grnxx/io/Makefile
lib/grnxx/map/Makefile
lib/grnxx/map/array_map/Makefile
lib/grnxx/map/hash_table/Makefile
lib/grnxx/storage/Makefile
src/Makefile
Expand Down
2 changes: 2 additions & 0 deletions lib/grnxx/map/Makefile.am
@@ -1,9 +1,11 @@
SUBDIRS = \
array_map \
hash_table

noinst_LTLIBRARIES = libgrnxx_map.la

libgrnxx_map_la_LIBADD = \
array_map/libgrnxx_map_array_map.la \
hash_table/libgrnxx_map_hash_table.la

libgrnxx_map_la_LDFLAGS = @AM_LTLDFLAGS@
Expand Down
1 change: 1 addition & 0 deletions lib/grnxx/map/array_map.cpp
Expand Up @@ -22,6 +22,7 @@
#include "grnxx/bytes.hpp"
#include "grnxx/geo_point.hpp"
#include "grnxx/logger.hpp"
#include "grnxx/map/helper.hpp"
#include "grnxx/storage.hpp"

namespace grnxx {
Expand Down
9 changes: 5 additions & 4 deletions lib/grnxx/map/array_map.hpp
Expand Up @@ -23,7 +23,8 @@
#include <memory>

#include "grnxx/map.hpp"
#include "grnxx/map/helper.hpp"
#include "grnxx/map/array_map/bit_array.hpp"
#include "grnxx/map/array_map/key_array.hpp"
#include "grnxx/types.hpp"

namespace grnxx {
Expand All @@ -36,14 +37,14 @@ struct ArrayMapHeader;

template <typename T>
class ArrayMap : public Map<T> {
using Bitmap = typename array_map::BitArray<T>::Type;
using KeyArray = typename array_map::KeyArray<T>::Type;

public:
using Key = typename Map<T>::Key;
using KeyArg = typename Map<T>::KeyArg;
using Cursor = typename Map<T>::Cursor;

using Bitmap = typename Helper<T>::Bitmap;
using KeyArray = typename Helper<T>::KeyArray;

ArrayMap();
~ArrayMap();

Expand Down
11 changes: 11 additions & 0 deletions lib/grnxx/map/array_map/Makefile.am
@@ -0,0 +1,11 @@
noinst_LTLIBRARIES = libgrnxx_map_array_map.la

libgrnxx_map_array_map_la_LDFLAGS = @AM_LTLDFLAGS@

libgrnxx_map_array_map_la_SOURCES = \
dummy.cpp

libgrnxx_map_array_map_includedir = ${includedir}/grnxx/map/array_map
libgrnxx_map_array_map_include_HEADERS = \
bit_array.hpp \
key_array.hpp
62 changes: 62 additions & 0 deletions lib/grnxx/map/array_map/bit_array.hpp
@@ -0,0 +1,62 @@
/*
Copyright (C) 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_BIT_ARRAY_HPP
#define GRNXX_MAP_ARRAY_MAP_BIT_ARRAY_HPP

#include "grnxx/features.hpp"

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

namespace grnxx {
namespace map {
namespace array_map {

// Change the array size based on the size of "T".
template <typename T, size_t T_SIZE = sizeof(T)>
struct BitArray;

// Map<T> has at most 2^40 different keys.
template <typename T, size_t T_SIZE>
struct BitArray {
using Type = Array<bool, 65536, 4096, 4096>;
};

// Map<T> has at most 2^8 different keys.
template <typename T>
struct BitArray<T, 1> {
using Type = Array<bool, 256, 1, 1>;
};

// Map<T> has at most 2^16 different keys.
template <typename T>
struct BitArray<T, 2> {
using Type = Array<bool, 256, 256, 1>;
};

// Map<T> has at most 2^32 different keys.
template <typename T>
struct BitArray<T, 4> {
using Type = Array<bool, 16384, 512, 512>;
};

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

#endif // GRNXX_MAP_ARRAY_MAP_BIT_ARRAY_HPP
27 changes: 27 additions & 0 deletions lib/grnxx/map/array_map/dummy.cpp
@@ -0,0 +1,27 @@
/*
Copyright (C) 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/bit_array.hpp"
#include "grnxx/map/array_map/key_array.hpp"

namespace grnxx {
namespace map {
namespace array_map {

} // namespace array_map
} // namespace map
} // namespace grnxx
70 changes: 70 additions & 0 deletions lib/grnxx/map/array_map/key_array.hpp
@@ -0,0 +1,70 @@
/*
Copyright (C) 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_KEY_ARRAY_HPP
#define GRNXX_MAP_ARRAY_MAP_KEY_ARRAY_HPP

#include "grnxx/features.hpp"

#include "grnxx/array.hpp"
#include "grnxx/bytes.hpp"
#include "grnxx/map/bytes_array.hpp"
#include "grnxx/types.hpp"

namespace grnxx {
namespace map {
namespace array_map {

// Change the array size based on "T".
template <typename T, size_t T_SIZE = sizeof(T)>
struct KeyArray;

// Map<T> has at most 2^40 different keys.
template <typename T, size_t T_SIZE>
struct KeyArray {
using Type = Array<T, 65536, 4096, 4096>;
};

// Map<T> has at most 2^8 different keys.
template <typename T>
struct KeyArray<T, 1> {
using Type = Array<T, 256, 1, 1>;
};

// Map<T> has at most 2^16 different keys.
template <typename T>
struct KeyArray<T, 2> {
using Type = Array<T, 256, 256, 1>;
};

// Map<T> has at most 2^32 different keys.
template <typename T>
struct KeyArray<T, 4> {
using Type = Array<T, 65536, 256, 256>;
};

// Map<T> has at most 2^40 different keys.
template <>
struct KeyArray<Bytes> {
using Type = BytesArray;
};

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

#endif // GRNXX_MAP_ARRAY_MAP_KEY_ARRAY_HPP
7 changes: 0 additions & 7 deletions lib/grnxx/map/hash_table/dummy.cpp
Expand Up @@ -15,11 +15,6 @@
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_HASH_TABLE_DUMMY_HPP
#define GRNXX_MAP_HASH_TABLE_DUMMY_HPP

#include "grnxx/features.hpp"

#include "grnxx/map/hash_table/bit_array.hpp"
#include "grnxx/map/hash_table/hash.hpp"
#include "grnxx/map/hash_table/key_array.hpp"
Expand All @@ -33,5 +28,3 @@ namespace hash_table {
} // namespace hash_table
} // namespace map
} // namespace grnxx

#endif // GRNXX_MAP_HASH_TABLE_DUMMY_HPP
2 changes: 1 addition & 1 deletion lib/grnxx/map/hash_table/key_array.hpp
Expand Up @@ -36,7 +36,7 @@ struct KeyArray;
// Map<T> has at most 2^40 different keys.
template <typename T, size_t T_SIZE>
struct KeyArray {
using Type = Array<T>;
using Type = Array<T, 65536, 4096, 4096>;
};

// Map<T> has at most 2^8 different keys.
Expand Down
52 changes: 0 additions & 52 deletions lib/grnxx/map/helper.hpp
Expand Up @@ -33,55 +33,6 @@
namespace grnxx {
namespace map {

// Change the settings based on the key type.
template <typename T, size_t T_SIZE = sizeof(T)>
struct BitmapHelper {
// Map<T> has at most 2^40 different keys.
using Type = Array<bool>;
};
template <typename T>
struct BitmapHelper<T, 1> {
// Map<T> has at most 2^8 different keys.
using Type = Array<bool, 256, 1, 1>;
};
template <typename T>
struct BitmapHelper<T, 2> {
// Map<T> has at most 2^16 different keys.
using Type = Array<bool, 256, 256, 1>;
};
template <typename T>
struct BitmapHelper<T, 4> {
// Map<T> has at most 2^32 different keys.
using Type = Array<bool, 65536, 256, 256>;
};

// Change the settings based on the key type.
template <typename T, size_t T_SIZE = sizeof(T)>
struct KeyArrayHelper {
// Map<T> has at most 2^40 different keys.
using Type = Array<T>;
};
template <typename T>
struct KeyArrayHelper<T, 1> {
// Map<T> has at most 2^8 different keys.
using Type = Array<T, 256, 1, 1>;
};
template <typename T>
struct KeyArrayHelper<T, 2> {
// Map<T> has at most 2^16 different keys.
using Type = Array<T, 256, 256, 1>;
};
template <typename T>
struct KeyArrayHelper<T, 4> {
// Map<T> has at most 2^32 different keys.
using Type = Array<T, 65536, 256, 256>;
};
template <>
struct KeyArrayHelper<Bytes> {
// Map<T> has at most 2^40 different keys.
using Type = BytesArray;
};

// Normalize a key.
template <typename T,
bool IS_FLOATING_POINT = std::is_floating_point<T>::value>
Expand Down Expand Up @@ -142,9 +93,6 @@ struct Helper {
using Key = typename Traits<T>::Type;
using KeyArg = typename Traits<T>::ArgumentType;

using Bitmap = typename BitmapHelper<T>::Type;
using KeyArray = typename KeyArrayHelper<T>::Type;

static Key normalize(KeyArg key) {
return NormalizeHelper<T>::normalize(key);
}
Expand Down

0 comments on commit a31db52

Please sign in to comment.