susumu.yata
null+****@clear*****
Tue Jun 23 10:31:21 JST 2015
susumu.yata 2015-06-23 10:31:21 +0900 (Tue, 23 Jun 2015) New Revision: 41195dc3339ebc081f3bb522a6f8042d0c8efaa9 https://github.com/groonga/grngo/commit/41195dc3339ebc081f3bb522a6f8042d0c8efaa9 Message: Support Time. GitHub: #2 Modified files: grngo.c grngo.go grngo.h Modified: grngo.c (+49 -0) =================================================================== --- grngo.c 2015-06-22 17:06:05 +0900 (a37b4fe) +++ grngo.c 2015-06-23 10:31:21 +0900 (36df50c) @@ -221,6 +221,11 @@ grngo_row_info grngo_table_insert_uint64(grn_ctx *ctx, grn_obj *table, return grngo_table_insert_row(ctx, table, &key, sizeof(key)); } +grngo_row_info grngo_table_insert_time(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_float(grn_ctx *ctx, grn_obj *table, double key) { return grngo_table_insert_row(ctx, table, &key, sizeof(key)); @@ -326,6 +331,16 @@ grn_bool grngo_column_set_uint64(grn_ctx *ctx, grn_obj *column, return rc == GRN_SUCCESS; } +grn_bool grngo_column_set_time(grn_ctx *ctx, grn_obj *column, + grn_id id, int64_t value) { + grn_obj obj; + GRN_TIME_INIT(&obj, 0); + GRN_TIME_SET(ctx, &obj, value); + grn_rc rc = grn_obj_set_value(ctx, column, id, &obj, GRN_OBJ_SET); + GRN_OBJ_FIN(ctx, &obj); + return rc == GRN_SUCCESS; +} + grn_bool grngo_column_set_float(grn_ctx *ctx, grn_obj *column, grn_id id, double value) { grn_obj obj; @@ -491,6 +506,20 @@ grn_bool grngo_column_set_uint64_vector(grn_ctx *ctx, grn_obj *column, return rc == GRN_SUCCESS; } +grn_bool grngo_column_set_time_vector(grn_ctx *ctx, grn_obj *column, + grn_id id, + const grngo_vector *value) { + grn_obj obj; + GRN_TIME_INIT(&obj, GRN_OBJ_VECTOR); + size_t i; + for (i = 0; i < value->size; i++) { + GRN_TIME_SET_AT(ctx, &obj, i, ((const int64_t *)value->ptr)[i]); + } + grn_rc rc = grn_obj_set_value(ctx, column, id, &obj, GRN_OBJ_SET); + GRN_OBJ_FIN(ctx, &obj); + return rc == GRN_SUCCESS; +} + grn_bool grngo_column_set_float_vector(grn_ctx *ctx, grn_obj *column, grn_id id, const grngo_vector *value) { @@ -604,6 +633,12 @@ grn_bool grngo_column_get_int(grn_ctx *ctx, grn_obj *column, *value = GRN_UINT64_VALUE(&value_obj); break; } + case GRN_DB_TIME: { + GRN_TIME_INIT(&value_obj, 0); + grn_obj_get_value(ctx, column, id, &value_obj); + *value = GRN_TIME_VALUE(&value_obj); + break; + } } GRN_OBJ_FIN(ctx, &value_obj); return GRN_TRUE; @@ -775,6 +810,20 @@ grn_bool grngo_column_get_int_vector(grn_ctx *ctx, grn_obj *column, value->size = size; break; } + case GRN_DB_TIME: { + GRN_TIME_INIT(&value_obj, GRN_OBJ_VECTOR); + grn_obj_get_value(ctx, column, id, &value_obj); + size_t size_in_bytes = GRN_BULK_VSIZE(&value_obj); + size_t size = size_in_bytes / sizeof(int64_t); + if (size <= value->size) { + size_t i; + for (i = 0; i < size; i++) { + ((int64_t *)value->ptr)[i] = GRN_TIME_VALUE_AT(&value_obj, i); + } + } + value->size = size; + break; + } } GRN_OBJ_FIN(ctx, &value_obj); return GRN_TRUE; Modified: grngo.go (+13 -1) =================================================================== --- grngo.go 2015-06-22 17:06:05 +0900 (f42d830) +++ grngo.go 2015-06-23 10:31:21 +0900 (0ec5d56) @@ -21,7 +21,7 @@ import ( // - Bool: bool // - (U)Int8/16/32/64: int64 // - Float: float64 -// - Time: TODO +// - Time: int64 // - WGS84/TokyoGeoPoint: GeoPoint // - (Short/Long)Text: []byte @@ -622,6 +622,9 @@ func (table *Table) insertInt(key int64) (bool, uint32, error) { case UInt64: grnKey := C.uint64_t(key) rowInfo = C.grngo_table_insert_uint64(table.db.ctx, table.obj, grnKey) + case Time: + grnKey := C.int64_t(key) + rowInfo = C.grngo_table_insert_time(table.db.ctx, table.obj, grnKey) default: return false, NilID, fmt.Errorf("key type conflict") } @@ -934,6 +937,9 @@ func (column *Column) setInt(id uint32, value int64) error { case UInt64: grnValue := C.uint64_t(value) ok = C.grngo_column_set_uint64(ctx, column.obj, C.grn_id(id), grnValue) + case Time: + grnValue := C.int64_t(value) + ok = C.grngo_column_set_time(ctx, column.obj, C.grn_id(id), grnValue) default: return fmt.Errorf("value type conflict") } @@ -1044,6 +1050,8 @@ func (column *Column) setIntVector(id uint32, value []int64) error { ok = C.grngo_column_set_uint32_vector(ctx, obj, C.grn_id(id), &grnVector) case UInt64: ok = C.grngo_column_set_uint64_vector(ctx, obj, C.grn_id(id), &grnVector) + case Time: + ok = C.grngo_column_set_time_vector(ctx, obj, C.grn_id(id), &grnVector) default: return fmt.Errorf("value type conflict") } @@ -1314,6 +1322,8 @@ func (column *Column) GetValue(id uint32) (interface{}, error) { return column.getInt(id) case Float: return column.getFloat(id) + case Time: + return column.getInt(id) case ShortText, Text, LongText: return column.getText(id) case TokyoGeoPoint, WGS84GeoPoint: @@ -1327,6 +1337,8 @@ func (column *Column) GetValue(id uint32) (interface{}, error) { return column.getIntVector(id) case Float: return column.getFloatVector(id) + case Time: + return column.getIntVector(id) case ShortText, Text, LongText: return column.getTextVector(id) case TokyoGeoPoint, WGS84GeoPoint: Modified: grngo.h (+7 -0) =================================================================== --- grngo.h 2015-06-22 17:06:05 +0900 (3ec6a42) +++ grngo.h 2015-06-23 10:31:21 +0900 (83bf02c) @@ -71,6 +71,8 @@ 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_row_info grngo_table_insert_time(grn_ctx *ctx, grn_obj *table, + int64_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); @@ -101,6 +103,8 @@ grn_bool grngo_column_set_uint32(grn_ctx *ctx, grn_obj *column, grn_id id, uint32_t value); grn_bool grngo_column_set_uint64(grn_ctx *ctx, grn_obj *column, grn_id id, uint64_t value); +grn_bool grngo_column_set_time(grn_ctx *ctx, grn_obj *column, + grn_id id, int64_t value); // grngo_column_set_float() assigns a Float value. grn_bool grngo_column_set_float(grn_ctx *ctx, grn_obj *column, grn_id id, double value); @@ -140,6 +144,9 @@ grn_bool grngo_column_set_uint32_vector(grn_ctx *ctx, grn_obj *column, grn_bool grngo_column_set_uint64_vector(grn_ctx *ctx, grn_obj *column, grn_id id, const grngo_vector *value); +grn_bool grngo_column_set_time_vector(grn_ctx *ctx, grn_obj *column, + grn_id id, + const grngo_vector *value); // grngo_column_set_float_vector() assigns a Float vector. grn_bool grngo_column_set_float_vector(grn_ctx *ctx, grn_obj *column, grn_id id, -------------- next part -------------- HTML����������������������������...Download