Example #1
0
func NewVector(size int) Vector {
	if size < 0 || uint64(size) > ^uint64(0) {
		panic(NewErr(fmt.Sprintf("Param 'size' out of range: %d", size)))
	}
	cfObj := C.cfish_Vec_new(C.size_t(size))
	return WRAPVector(unsafe.Pointer(cfObj))
}
Example #2
0
func spanSliceToVec(slice []Span) *C.cfish_Vector {
	if slice == nil {
		return nil
	}
	length := len(slice)
	vec := C.cfish_Vec_new(C.size_t(length))
	for i := 0; i < length; i++ {
		elem := clownfish.Unwrap(slice[i], "slice[i]")
		C.CFISH_Vec_Push(vec, C.cfish_incref(elem))
	}
	return vec
}
Example #3
0
File: lucy.go Project: apache/lucy
// Turn a slice of Go strings into a Vector of Clownfish Strings.
func stringSliceToVec(strings []string) *C.cfish_Vector {
	if strings == nil {
		return nil
	}
	size := len(strings)
	vec := C.cfish_Vec_new(C.size_t(size))
	for i := 0; i < size; i++ {
		str := C.CString(strings[i])
		length := C.size_t(len(strings[i]))
		cfStr := C.cfish_Str_new_steal_utf8(str, length)
		C.CFISH_Vec_Push(vec, (*C.cfish_Obj)(unsafe.Pointer(cfStr)))
	}
	return vec
}
Example #4
0
func (d *DataReaderIMP) Aggregator(readers []DataReader, offsets []int32) (retval DataReader, err error) {
	err = clownfish.TrapErr(func() {
		self := (*C.lucy_DataReader)(clownfish.Unwrap(d, "d"))
		size := len(readers)
		readersC := C.cfish_Vec_new(C.size_t(size))
		defer C.cfish_decref(unsafe.Pointer(readersC))
		for i := 0; i < size; i++ {
			elemC := clownfish.Unwrap(readers[i], "readers[i]")
			C.CFISH_Vec_Push(readersC, C.cfish_incref(elemC))
		}
		offs := NewI32Array(offsets)
		offsetsC := (*C.lucy_I32Array)(clownfish.Unwrap(offs, "offs"))
		retvalCF := C.LUCY_DataReader_Aggregator(self, readersC, offsetsC)
		defer C.cfish_decref(unsafe.Pointer(retvalCF))
		if retvalCF != nil {
			retval = clownfish.ToGo(unsafe.Pointer(retvalCF)).(DataReader)
		}
	})
	return retval, err
}
Example #5
0
func goToVector(value interface{}, nullable bool) unsafe.Pointer {
	switch v := value.(type) {
	case []interface{}:
		if v == nil {
			if nullable {
				return nil
			}
		} else {
			size := len(v)
			vec := C.cfish_Vec_new(C.size_t(size))
			for i := 0; i < size; i++ {
				elem := GoToClownfish(v[i], nil, true)
				C.CFISH_Vec_Store(vec, C.size_t(i), (*C.cfish_Obj)(elem))
			}
			return unsafe.Pointer(vec)
		}
	case Obj:
		certifyCF(v, C.CFISH_VECTOR, nullable)
		return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR())))
	}
	mess := fmt.Sprintf("Can't convert %T to clownfish.Vector", value)
	panic(NewErr(mess))
}