[Groonga-commit] groonga/grnxx [master] Avoid small_value-related problems.

Back to archive index

susumu.yata null+****@clear*****
Mon Apr 8 11:22:55 JST 2013


susumu.yata	2013-04-08 11:22:55 +0900 (Mon, 08 Apr 2013)

  New Revision: eeca95466a0078e5022a5f6938584601e92c2ffc
  https://github.com/groonga/grnxx/commit/eeca95466a0078e5022a5f6938584601e92c2ffc

  Message:
    Avoid small_value-related problems.

  Modified files:
    lib/grnxx/alpha/map/array.cpp
    test/test_alpha_map.cpp

  Modified: lib/grnxx/alpha/map/array.cpp (+12 -6)
===================================================================
--- lib/grnxx/alpha/map/array.cpp    2013-04-08 10:40:32 +0900 (cf3d912)
+++ lib/grnxx/alpha/map/array.cpp    2013-04-08 11:22:55 +0900 (6533f2e)
@@ -18,6 +18,7 @@
 #include "grnxx/alpha/map/array.hpp"
 
 #include <cmath>
+#include <string>
 
 namespace grnxx {
 namespace alpha {
@@ -47,12 +48,14 @@ struct Helper<T, false> {
   }
 };
 
-db::Blob slice_to_blob(Slice slice) {
-  return db::Blob(slice.ptr(), slice.size());
+db::Blob slice_to_blob(Slice slice, std::string *buf) {
+  buf->assign(reinterpret_cast<const char *>(slice.ptr()), slice.size());
+  buf->resize(buf->size() + 7, ' ');
+  return db::Blob(buf->data(), buf->size());
 }
 
 Slice blob_to_slice(const db::Blob &blob) {
-  return Slice(blob.address(), blob.length());
+  return Slice(blob.address(), blob.length() - 7);
 }
 
 }  // namespace
@@ -324,7 +327,8 @@ bool Array<Slice>::reset(int64_t key_id, Slice dest_key) {
   if (!dest_key || search(dest_key)) {
     return false;
   }
-  keys_[key_id] = slice_to_blob(dest_key);
+  std::string buf;
+  keys_[key_id] = slice_to_blob(dest_key, &buf);
   return true;
 }
 
@@ -361,7 +365,8 @@ bool Array<Slice>::insert(Slice key, int64_t *key_id) {
   if (key_id_candidate == -1) {
     key_id_candidate = ++header_->max_key_id;
   }
-  keys_[key_id_candidate] = slice_to_blob(key);
+  std::string buf;
+  keys_[key_id_candidate] = slice_to_blob(key, &buf);
   if (key_id) {
     *key_id = key_id_candidate;
   }
@@ -385,7 +390,8 @@ bool Array<Slice>::update(Slice src_key, Slice dest_key, int64_t *key_id) {
   if (!dest_key || search(dest_key)) {
     return false;
   }
-  keys_[src_key_id] = slice_to_blob(dest_key);
+  std::string buf;
+  keys_[src_key_id] = slice_to_blob(dest_key, &buf);
   if (key_id) {
     *key_id = src_key_id;
   }

  Modified: test/test_alpha_map.cpp (+2 -2)
===================================================================
--- test/test_alpha_map.cpp    2013-04-08 10:40:32 +0900 (fed0912)
+++ test/test_alpha_map.cpp    2013-04-08 11:22:55 +0900 (3003d8f)
@@ -79,8 +79,8 @@ void generate_key(grnxx::Slice *key) {
   static std::mt19937_64 rng;
   static std::vector<std::string> keys;
 
-  const std::size_t MIN_SIZE = 8;  // TODO: should be 1 in future.
-  const std::size_t MAX_SIZE = 100;  // TODO: should be 4096 in future.
+  const std::size_t MIN_SIZE = 1;
+  const std::size_t MAX_SIZE = 16;  // TODO: should be 4096 in future.
 
   std::size_t size = MIN_SIZE + (rng() % (MAX_SIZE - MIN_SIZE + 1));
   std::string key_buf;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index