[Groonga-commit] groonga/grngo at f379f26 [master] Support integer keys other than Int64.

Back to archive index

susumu.yata null+****@clear*****
Mon Jun 22 15:02:45 JST 2015


susumu.yata	2015-06-22 15:02:45 +0900 (Mon, 22 Jun 2015)

  New Revision: f379f26eddcc490cf94617d19d6c5fc0e5251c4d
  https://github.com/groonga/grngo/commit/f379f26eddcc490cf94617d19d6c5fc0e5251c4d

  Message:
    Support integer keys other than Int64.
    
    GitHub: #5

  Modified files:
    grngo.c
    grngo.go
    grngo.h

  Modified: grngo.c (+37 -2)
===================================================================
--- grngo.c    2015-06-22 13:47:49 +0900 (de3c639)
+++ grngo.c    2015-06-22 15:02:45 +0900 (626596c)
@@ -181,8 +181,43 @@ grngo_row_info grngo_table_insert_bool(grn_ctx *ctx, grn_obj *table,
   return grngo_table_insert_row(ctx, table, &key, sizeof(key));
 }
 
-grngo_row_info grngo_table_insert_int(grn_ctx *ctx, grn_obj *table,
-                                      int64_t key) {
+grngo_row_info grngo_table_insert_int8(grn_ctx *ctx, grn_obj *table,
+                                       int8_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_int16(grn_ctx *ctx, grn_obj *table,
+                                        int16_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_int32(grn_ctx *ctx, grn_obj *table,
+                                        int32_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_int64(grn_ctx *ctx, grn_obj *table,
+                                        int64_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_uint8(grn_ctx *ctx, grn_obj *table,
+                                        uint8_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_uint16(grn_ctx *ctx, grn_obj *table,
+                                         uint16_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_uint32(grn_ctx *ctx, grn_obj *table,
+                                         uint32_t key) {
+  return grngo_table_insert_row(ctx, table, &key, sizeof(key));
+}
+
+grngo_row_info grngo_table_insert_uint64(grn_ctx *ctx, grn_obj *table,
+                                         uint64_t key) {
   return grngo_table_insert_row(ctx, table, &key, sizeof(key));
 }
 

  Modified: grngo.go (+26 -4)
===================================================================
--- grngo.go    2015-06-22 13:47:49 +0900 (4411ff7)
+++ grngo.go    2015-06-22 15:02:45 +0900 (3a4d0cd)
@@ -596,15 +596,37 @@ func (table *Table) insertBool(key bool) (bool, uint32, error) {
 
 // insertInt() inserts a row with Int key.
 func (table *Table) insertInt(key int64) (bool, uint32, error) {
+	var rowInfo C.grngo_row_info
 	switch table.keyType {
-	case Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64:
+	case Int8:
+		grnKey := C.int8_t(key)
+		rowInfo = C.grngo_table_insert_int8(table.db.ctx, table.obj, grnKey)
+	case Int16:
+		grnKey := C.int16_t(key)
+		rowInfo = C.grngo_table_insert_int16(table.db.ctx, table.obj, grnKey)
+	case Int32:
+		grnKey := C.int32_t(key)
+		rowInfo = C.grngo_table_insert_int32(table.db.ctx, table.obj, grnKey)
+	case Int64:
+		grnKey := C.int64_t(key)
+		rowInfo = C.grngo_table_insert_int64(table.db.ctx, table.obj, grnKey)
+	case UInt8:
+		grnKey := C.uint8_t(key)
+		rowInfo = C.grngo_table_insert_uint8(table.db.ctx, table.obj, grnKey)
+	case UInt16:
+		grnKey := C.uint16_t(key)
+		rowInfo = C.grngo_table_insert_uint16(table.db.ctx, table.obj, grnKey)
+	case UInt32:
+		grnKey := C.uint32_t(key)
+		rowInfo = C.grngo_table_insert_uint32(table.db.ctx, table.obj, grnKey)
+	case UInt64:
+		grnKey := C.uint64_t(key)
+		rowInfo = C.grngo_table_insert_uint64(table.db.ctx, table.obj, grnKey)
 	default:
 		return false, NilID, fmt.Errorf("key type conflict")
 	}
-	grnKey := C.int64_t(key)
-	rowInfo := C.grngo_table_insert_int(table.db.ctx, table.obj, grnKey)
 	if rowInfo.id == C.GRN_ID_NIL {
-		return false, NilID, fmt.Errorf("grngo_table_insert_int() failed")
+		return false, NilID, fmt.Errorf("grngo_table_insert_int*() failed")
 	}
 	return rowInfo.inserted == C.GRN_TRUE, uint32(rowInfo.id), nil
 }

  Modified: grngo.h (+17 -3)
===================================================================
--- grngo.h    2015-06-22 13:47:49 +0900 (726d6a1)
+++ grngo.h    2015-06-22 15:02:45 +0900 (d82e5a3)
@@ -54,9 +54,23 @@ grngo_row_info grngo_table_insert_void(grn_ctx *ctx, grn_obj *table);
 // grngo_table_insert_bool() inserts a row with Bool key.
 grngo_row_info grngo_table_insert_bool(grn_ctx *ctx, grn_obj *table,
                                        grn_bool key);
-// grngo_table_insert_int() inserts a row with Int key.
-grngo_row_info grngo_table_insert_int(grn_ctx *ctx, grn_obj *table,
-                                      int64_t key);
+// grngo_table_insert_int*() inserts a row with Int key.
+grngo_row_info grngo_table_insert_int8(grn_ctx *ctx, grn_obj *table,
+                                       int8_t key);
+grngo_row_info grngo_table_insert_int16(grn_ctx *ctx, grn_obj *table,
+                                        int16_t key);
+grngo_row_info grngo_table_insert_int32(grn_ctx *ctx, grn_obj *table,
+                                        int32_t key);
+grngo_row_info grngo_table_insert_int64(grn_ctx *ctx, grn_obj *table,
+                                        int64_t key);
+grngo_row_info grngo_table_insert_uint8(grn_ctx *ctx, grn_obj *table,
+                                        uint8_t key);
+grngo_row_info grngo_table_insert_uint16(grn_ctx *ctx, grn_obj *table,
+                                         uint16_t key);
+grngo_row_info grngo_table_insert_uint32(grn_ctx *ctx, grn_obj *table,
+                                         uint32_t key);
+grngo_row_info grngo_table_insert_uint64(grn_ctx *ctx, grn_obj *table,
+                                         uint64_t key);
 // grngo_table_insert_float() inserts a row with Float key.
 grngo_row_info grngo_table_insert_float(grn_ctx *ctx, grn_obj *table,
                                         double key);
-------------- next part --------------
HTML����������������������������...
Descargar 



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