[Groonga-commit] groonga/grnxx at 0b7f7c3 [master] Add get/set() to Array and ArrayRef.

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Fri Aug 8 12:47:54 JST 2014


susumu.yata	2014-08-08 12:47:54 +0900 (Fri, 08 Aug 2014)

  New Revision: 0b7f7c396541e8addfca879a3cfa94dc5ab8d003
  https://github.com/groonga/grnxx/commit/0b7f7c396541e8addfca879a3cfa94dc5ab8d003

  Message:
    Add get/set() to Array and ArrayRef.

  Modified files:
    include/grnxx/array.hpp

  Modified: include/grnxx/array.hpp (+38 -0)
===================================================================
--- include/grnxx/array.hpp    2014-08-08 12:28:32 +0900 (0189126)
+++ include/grnxx/array.hpp    2014-08-08 12:47:54 +0900 (464e1b8)
@@ -28,6 +28,13 @@ class ArrayRef {
     return ArrayRef(values_ + offset, size);
   }
 
+  T get(Int i) const {
+    return values_[i];
+  }
+  void set(Int i, T value) {
+    values_[i] = value;
+  }
+
   T &operator[](Int i) {
     return values_[i];
   }
@@ -64,6 +71,13 @@ class Array {
     return ArrayRef<T>(const_cast<T *>(data()) + offset, size);
   }
 
+  T get(Int i) const {
+    return values_[i];
+  }
+  void set(Int i, T value) {
+    values_[i] = value;
+  }
+
   T &operator[](Int i) {
     return values_[static_cast<size_t>(i)];
   }
@@ -223,6 +237,19 @@ class ArrayRef<Bool> {
     return ArrayRef(blocks_, offset, size);
   }
 
+  Bool get(Int i) const {
+    i += static_cast<Int>(offset_);
+    return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
+  }
+  void set(Int i, Bool value) {
+    i += static_cast<Int>(offset_);
+    if (value) {
+      blocks_[i / 64] |= uint64_t(1) << (i % 64);
+    } else {
+      blocks_[i / 64] &= ~(uint64_t(1) << (i % 64));
+    }
+  }
+
   BoolReference operator[](Int i) {
     i += static_cast<Int>(offset_);
     return BoolReference(&blocks_[i / 64], uint64_t(1) << (i % 64));
@@ -275,6 +302,17 @@ class Array<Bool> {
     return ArrayRef<Bool>(const_cast<uint64_t *>(blocks()), offset, size);
   }
 
+  Bool get(Int i) const {
+    return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
+  }
+  void set(Int i, Bool value) {
+    if (value) {
+      blocks_[i / 64] |= uint64_t(1) << (i % 64);
+    } else {
+      blocks_[i / 64] &= ~(uint64_t(1) << (i % 64));
+    }
+  }
+
   BoolReference operator[](Int i) {
     return BoolReference(&blocks_[i / 64], uint64_t(1) << (i % 64));
   }
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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