[Groonga-commit] groonga/grnxx at 2c8075f [master] Add a new interface to create a cursor.

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Mon May 6 16:18:38 JST 2013


susumu.yata	2013-05-06 16:18:38 +0900 (Mon, 06 May 2013)

  New Revision: 2c8075f44b3935a09361053db70de5a3d80d05d3
  https://github.com/groonga/grnxx/commit/2c8075f44b3935a09361053db70de5a3d80d05d3

  Message:
    Add a new interface to create a cursor.

  Added files:
    lib/grnxx/alpha/map_range.hpp
  Modified files:
    lib/grnxx/alpha/Makefile.am
    lib/grnxx/alpha/map.cpp
    lib/grnxx/alpha/map.hpp

  Modified: lib/grnxx/alpha/Makefile.am (+1 -0)
===================================================================
--- lib/grnxx/alpha/Makefile.am    2013-05-06 12:20:10 +0900 (2340390)
+++ lib/grnxx/alpha/Makefile.am    2013-05-06 16:18:38 +0900 (7895a75)
@@ -17,4 +17,5 @@ libgrnxx_alpha_include_HEADERS =	\
 	double_array.hpp		\
 	geo_point.hpp			\
 	map.hpp				\
+	map_range.hpp			\
 	sample.hpp

  Modified: lib/grnxx/alpha/map.cpp (+95 -0)
===================================================================
--- lib/grnxx/alpha/map.cpp    2013-05-06 12:20:10 +0900 (ca3456f)
+++ lib/grnxx/alpha/map.cpp    2013-05-06 16:18:38 +0900 (d1b6ab6)
@@ -324,6 +324,101 @@ MapCursor<Slice> *Map<Slice>::open_reverse_completion_cursor(
 }
 
 template <typename T>
+MapCursor<T> *Map<T>::open_cursor(const MapIDRange &range,
+                                  const MapCursorOptions &options) {
+  int64_t min = -1;
+  int64_t max = -1;
+  MapCursorOptions options_clone = options;
+  options_clone.flags &= ~(MAP_CURSOR_EXCEPT_MIN | MAP_CURSOR_EXCEPT_MAX);
+  if (range.flags & (MAP_RANGE_GREATER | MAP_RANGE_GREATER_EQUAL)) {
+    min = range.min;
+    if (range.flags & MAP_RANGE_GREATER) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MIN;
+    }
+  }
+  if (range.flags & (MAP_RANGE_LESS | MAP_RANGE_LESS_EQUAL)) {
+    max = range.max;
+    if (range.flags & MAP_RANGE_LESS) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MAX;
+    }
+  }
+  return new (std::nothrow) map::IDCursor<T>(this, min, max, options_clone);
+}
+
+template <typename T>
+MapCursor<T> *Map<T>::open_cursor(const MapKeyRange<T> &range,
+                                  const MapCursorOptions &options) {
+  T min = std::numeric_limits<T>::min();
+  T max = std::numeric_limits<T>::max();
+  MapCursorOptions options_clone = options;
+  options_clone.flags &= ~(MAP_CURSOR_EXCEPT_MIN | MAP_CURSOR_EXCEPT_MAX);
+  if (range.flags & (MAP_RANGE_GREATER | MAP_RANGE_GREATER_EQUAL)) {
+    min = range.min;
+    if (range.flags & MAP_RANGE_GREATER) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MIN;
+    }
+  }
+  if (range.flags & (MAP_RANGE_LESS | MAP_RANGE_LESS_EQUAL)) {
+    max = range.max;
+    if (range.flags & MAP_RANGE_LESS) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MAX;
+    }
+  }
+  return new (std::nothrow) map::KeyCursor<T>(this, min, max, options_clone);
+}
+
+template <>
+MapCursor<double> *Map<double>::open_cursor(
+    const MapKeyRange<double> &range, const MapCursorOptions &options) {
+  double min = -std::numeric_limits<double>::infinity();
+  double max = +std::numeric_limits<double>::infinity();
+  MapCursorOptions options_clone = options;
+  options_clone.flags &= ~(MAP_CURSOR_EXCEPT_MIN | MAP_CURSOR_EXCEPT_MAX);
+  if (range.flags & (MAP_RANGE_GREATER | MAP_RANGE_GREATER_EQUAL)) {
+    min = range.min;
+    if (range.flags & MAP_RANGE_GREATER) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MIN;
+    }
+  }
+  if (range.flags & (MAP_RANGE_LESS | MAP_RANGE_LESS_EQUAL)) {
+    max = range.max;
+    if (range.flags & MAP_RANGE_LESS) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MAX;
+    }
+  }
+  return new (std::nothrow) map::KeyCursor<double>(this, min, max, options_clone);
+}
+
+template <>
+MapCursor<GeoPoint> *Map<GeoPoint>::open_cursor(
+    const MapKeyRange<GeoPoint> &, const MapCursorOptions &) {
+  // Not supported.
+  return nullptr;
+}
+
+template <>
+MapCursor<Slice> *Map<Slice>::open_cursor(
+    const MapKeyRange<Slice> &range, const MapCursorOptions &options) {
+  Slice min = nullptr;
+  Slice max = nullptr;
+  MapCursorOptions options_clone = options;
+  options_clone.flags &= ~(MAP_CURSOR_EXCEPT_MIN | MAP_CURSOR_EXCEPT_MAX);
+  if (range.flags & (MAP_RANGE_GREATER | MAP_RANGE_GREATER_EQUAL)) {
+    min = range.min;
+    if (range.flags & MAP_RANGE_GREATER) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MIN;
+    }
+  }
+  if (range.flags & (MAP_RANGE_LESS | MAP_RANGE_LESS_EQUAL)) {
+    max = range.max;
+    if (range.flags & MAP_RANGE_LESS) {
+      options_clone.flags |= MAP_CURSOR_EXCEPT_MAX;
+    }
+  }
+  return new (std::nothrow) map::KeyCursor<Slice>(this, min, max, options_clone);
+}
+
+template <typename T>
 MapScan<T> *Map<T>::open_scan(T, const Charset *) {
   // Not supported
   return nullptr;

  Modified: lib/grnxx/alpha/map.hpp (+15 -0)
===================================================================
--- lib/grnxx/alpha/map.hpp    2013-05-06 12:20:10 +0900 (e3e561b)
+++ lib/grnxx/alpha/map.hpp    2013-05-06 16:18:38 +0900 (656d87b)
@@ -18,6 +18,7 @@
 #ifndef GRNXX_ALPHA_MAP_HPP
 #define GRNXX_ALPHA_MAP_HPP
 
+#include "grnxx/alpha/map_range.hpp"
 #include "grnxx/io/pool.hpp"
 #include "grnxx/slice.hpp"
 
@@ -177,6 +178,20 @@ class Map {
   virtual MapCursor<T> *open_reverse_completion_cursor(
       T query, const MapCursorOptions &options = MapCursorOptions());
 
+  MapID id() const {
+    return MapID();
+  }
+  MapKey<T> key() const {
+    return MapKey<T>();
+  }
+
+  virtual MapCursor<T> *open_cursor(
+      const MapIDRange &range,
+      const MapCursorOptions &options = MapCursorOptions());
+  virtual MapCursor<T> *open_cursor(
+      const MapKeyRange<T> &range,
+      const MapCursorOptions &options = MapCursorOptions());
+
   // Only for Slice.
   // Create a MapScan object to find keys in "query".
   virtual MapScan<T> *open_scan(T query, const Charset *charset = nullptr);

  Added: lib/grnxx/alpha/map_range.hpp (+264 -0) 100644
===================================================================
--- /dev/null
+++ lib/grnxx/alpha/map_range.hpp    2013-05-06 16:18:38 +0900 (77ed7c3)
@@ -0,0 +1,264 @@
+/*
+  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_ALPHA_MAP_RANGE_HPP
+#define GRNXX_ALPHA_MAP_RANGE_HPP
+
+#include "grnxx/basic.hpp"
+#include "grnxx/flags_impl.hpp"
+
+namespace grnxx {
+namespace alpha {
+
+struct MapRangeFlagsIdentifier;
+using MapRangeFlags = FlagsImpl<MapRangeFlagsIdentifier>;
+
+constexpr MapRangeFlags MAP_RANGE_DEFAULT       = MapRangeFlags::define(0x00);
+constexpr MapRangeFlags MAP_RANGE_LESS          = MapRangeFlags::define(0x01);
+constexpr MapRangeFlags MAP_RANGE_LESS_EQUAL    = MapRangeFlags::define(0x02);
+constexpr MapRangeFlags MAP_RANGE_GREATER       = MapRangeFlags::define(0x04);
+constexpr MapRangeFlags MAP_RANGE_GREATER_EQUAL = MapRangeFlags::define(0x08);
+
+struct MapID {};
+
+struct MapIDRange {
+  int64_t min;
+  int64_t max;
+  MapRangeFlags flags;
+};
+
+struct MapIDLess {
+  int64_t max;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_LESS;
+  }
+  operator MapIDRange() const {
+    return MapIDRange{ int64_t(), max, flags() };
+  }
+};
+
+struct MapIDLessEqual {
+  int64_t max;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_LESS_EQUAL;
+  }
+  operator MapIDRange() const {
+    return MapIDRange{ int64_t(), max, flags() };
+  }
+};
+
+struct MapIDGreater {
+  int64_t min;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_GREATER;
+  }
+  operator MapIDRange() const {
+    return MapIDRange{ min, int64_t(), flags() };
+  }
+};
+
+struct MapIDGreaterEqual {
+  int64_t min;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_GREATER_EQUAL;
+  }
+  operator MapIDRange() const {
+    return MapIDRange{ min, int64_t(), flags() };
+  }
+};
+
+inline MapIDLess operator<(MapID, int64_t max) {
+  return MapIDLess{ max };
+}
+inline MapIDLessEqual operator<=(MapID, int64_t max) {
+  return MapIDLessEqual{ max };
+}
+inline MapIDGreater operator>(MapID, int64_t min) {
+  return MapIDGreater{ min };
+}
+inline MapIDGreaterEqual operator>=(MapID, int64_t min) {
+  return MapIDGreaterEqual{ min };
+}
+
+inline MapIDGreater operator<(int64_t min, MapID) {
+  return MapIDGreater{ min };
+}
+inline MapIDGreaterEqual operator<=(int64_t min, MapID) {
+  return MapIDGreaterEqual{ min };
+}
+inline MapIDLess operator>(int64_t max, MapID) {
+  return MapIDLess{ max };
+}
+inline MapIDLessEqual operator>=(int64_t max, MapID) {
+  return MapIDLessEqual{ max };
+}
+
+inline MapIDRange operator&&(MapIDLess less, MapIDGreater greater) {
+  return MapIDRange{ greater.min, less.max, less.flags() | greater.flags() };
+}
+inline MapIDRange operator&&(MapIDLess less, MapIDGreaterEqual greater) {
+  return MapIDRange{ greater.min, less.max, less.flags() | greater.flags() };
+}
+inline MapIDRange operator&&(MapIDLessEqual less, MapIDGreater greater) {
+  return MapIDRange{ greater.min, less.max, less.flags() | greater.flags() };
+}
+inline MapIDRange operator&&(MapIDLessEqual less, MapIDGreaterEqual greater) {
+  return MapIDRange{ greater.min, less.max, less.flags() | greater.flags() };
+}
+inline MapIDRange operator&&(MapIDGreater greater, MapIDLess less) {
+  return less && greater;
+}
+inline MapIDRange operator&&(MapIDGreater greater, MapIDLessEqual less) {
+  return less && greater;
+}
+inline MapIDRange operator&&(MapIDGreaterEqual greater, MapIDLess less) {
+  return less && greater;
+}
+inline MapIDRange operator&&(MapIDGreaterEqual greater, MapIDLessEqual less) {
+  return less && greater;
+}
+
+template <typename T> struct MapKey {};
+
+template <typename T>
+struct MapKeyRange {
+  T min;
+  T max;
+  MapRangeFlags flags;
+};
+
+template <typename T>
+struct MapKeyLess {
+  T max;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_LESS;
+  }
+  operator MapKeyRange<T>() const {
+    return MapKeyRange<T>{ int64_t(), max, flags() };
+  }
+};
+
+template <typename T>
+struct MapKeyLessEqual {
+  T max;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_LESS_EQUAL;
+  }
+  operator MapKeyRange<T>() const {
+    return MapKeyRange<T>{ int64_t(), max, flags() };
+  }
+};
+
+template <typename T>
+struct MapKeyGreater {
+  T min;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_GREATER;
+  }
+  operator MapKeyRange<T>() const {
+    return MapKeyRange<T>{ min, int64_t(), flags() };
+  }
+};
+
+template <typename T>
+struct MapKeyGreaterEqual {
+  T min;
+  constexpr MapRangeFlags flags() {
+    return MAP_RANGE_GREATER_EQUAL;
+  }
+  operator MapKeyRange<T>() const {
+    return MapKeyRange<T>{ min, int64_t(), flags() };
+  }
+};
+
+template <typename T>
+MapKeyLess<T> operator<(MapKey<T>, T max) {
+  return MapKeyLess<T>{ max };
+}
+template <typename T>
+MapKeyLessEqual<T> operator<=(MapKey<T>, T max) {
+  return MapKeyLessEqual<T>{ max };
+}
+template <typename T>
+MapKeyGreater<T> operator>(MapKey<T>, T min) {
+  return MapKeyGreater<T>{ min };
+}
+template <typename T>
+MapKeyGreaterEqual<T> operator>=(MapKey<T>, T min) {
+  return MapKeyGreaterEqual<T>{ min };
+}
+
+template <typename T>
+MapKeyGreater<T> operator<(T min, MapKey<T>) {
+  return MapKeyGreater<T>{ min };
+}
+template <typename T>
+MapKeyGreaterEqual<T> operator<=(T min, MapKey<T>) {
+  return MapKeyGreaterEqual<T>{ min };
+}
+template <typename T>
+MapKeyLess<T> operator>(T max, MapKey<T>) {
+  return MapKeyLess<T>{ max };
+}
+template <typename T>
+MapKeyLessEqual<T> operator>=(T max, MapKey<T>) {
+  return MapKeyLessEqual<T>{ max };
+}
+
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyLess<T> less, MapKeyGreater<T> greater) {
+  return MapKeyRange<T>{ greater.min, less.max,
+                         less.flags() | greater.flags() };
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyLess<T> less, MapKeyGreaterEqual<T> greater) {
+  return MapKeyRange<T>{ greater.min, less.max,
+                         less.flags() | greater.flags() };
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyLessEqual<T> less, MapKeyGreater<T> greater) {
+  return MapKeyRange<T>{ greater.min, less.max,
+                         less.flags() | greater.flags() };
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyLessEqual<T> less,
+                          MapKeyGreaterEqual<T> greater) {
+  return MapKeyRange<T>{ greater.min, less.max,
+                         less.flags() | greater.flags() };
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyGreater<T> greater, MapKeyLess<T> less) {
+  return less && greater;
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyGreater<T> greater, MapKeyLessEqual<T> less) {
+  return less && greater;
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyGreaterEqual<T> greater, MapKeyLess<T> less) {
+  return less && greater;
+}
+template <typename T>
+MapKeyRange<T> operator&&(MapKeyGreaterEqual<T> greater,
+                          MapKeyLessEqual<T> less) {
+  return less && greater;
+}
+
+}  // namespace alpha
+}  // namespace grnxx
+
+#endif  // GRNXX_ALPHA_MAP_RANGE_HPP
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る