示例#1
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) Test(index uint64) (exists bool) {
	st := C.Judy1Test(C.Pcvoid_t(j.val), C.Word_t(index), nil)
	if st != 0 {
		exists = true
	}
	return
}
示例#2
0
文件: judyl.go 项目: riobard/go-judy
// Get the Value associated with Index in the Judy array
//   returns (value, true) if the index was found
//   returns (_, false) if the index was not found
func (j *JudyL) Get(index uint64) (uint64, bool) {
	pval := unsafe.Pointer(C.JudyLGet(C.Pcvoid_t(j.array), C.Word_t(index), nil))
	if pval == nil {
		return 0, false
	} else {
		return uint64(*((*C.Word_t)(pval))), true
	}
}
示例#3
0
文件: judy1.go 项目: riobard/go-judy
// Search (inclusive) for the first index present that is equal to or greater than the passed index.
// (Start with index = 0 to find the first index in the array.) This is typically used to begin a sorted-order scan of the indexes present in a Judy1 array.
//
//   index - search index
//   returns uint64 - value of the first index that is equal to or greater than the passed index (only if bool return value is true)
//           bool   - true if the search was successful, false if an index was not found
func (j *Judy1) First(index uint64) (uint64, bool) {
	var idx C.Word_t = C.Word_t(index)

	if C.Judy1First(C.Pcvoid_t(j.array), &idx, nil) != 0 {
		return uint64(idx), true
	} else {
		return 0, false
	}
}
示例#4
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) Prev(index uint64) (prevIndex uint64, found bool) {
	index0 := C.Word_t(index)
	st := C.Judy1Prev(C.Pcvoid_t(j.val), &index0, nil)
	if st != 0 {
		prevIndex = uint64(index0)
		found = true
	}
	return
}
示例#5
0
文件: judy1.go 项目: riobard/go-judy
// Locate the Nth index that is present in the Judy1 array (Nth = 1 returns the first index present).
//
//   nth - nth index to find
//   returns uint64 - nth index (unless return false))
//           bool   - true if the search was successful, false if an index was not found
func (j *Judy1) ByCount(nth uint64) (uint64, bool) {
	var idx C.Word_t

	if C.Judy1ByCount(C.Pcvoid_t(j.array), C.Word_t(nth), &idx, nil) != 0 {
		return uint64(idx), true
	} else {
		return 0, false
	}
}
示例#6
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) First(index uint64) (firstIndex uint64, found bool) {
	index0 := C.Word_t(index)
	st := C.Judy1First(C.Pcvoid_t(j.val), &index0, nil)
	if st != 0 {
		firstIndex = uint64(index0)
		found = true
	}
	return
}
示例#7
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) NextEmpty(index uint64) (nextIndex uint64, found bool) {
	index0 := C.Word_t(index)
	st := C.Judy1NextEmpty(C.Pcvoid_t(j.val), &index0, nil)
	if st != 0 {
		nextIndex = uint64(index0)
		found = true
	}
	return
}
示例#8
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) ByCount(count uint64) (index uint64, found bool) {
	var ret C.Word_t = 0
	st := C.Judy1ByCount(C.Pcvoid_t(j.val), C.Word_t(count), &ret, nil)
	if st == 1 {
		found = true
		index = uint64(ret)
	}
	return
}
示例#9
0
文件: judyl.go 项目: riobard/go-judy
// Search (inclusive) for the first index present that is equal to or greater than the passed index.
// (Start with index = 0 to find the first index in the array.) This is typically used to begin a sorted-order scan of the indexes present in a JudyL array.
//
//   index - search index
//   returns uint64 - value of the first index that is equal to or greater than the passed index
//                    (only if bool return value is true)
//           uint64 - value pointed to by the index
//           bool   - true if the search was successful, false if an index was not found
func (j *JudyL) First(index uint64) (uint64, uint64, bool) {
	idx := C.Word_t(index)
	pval := unsafe.Pointer(C.JudyLFirst(C.Pcvoid_t(j.array), &idx, nil))

	if pval == nil {
		return 0, 0, false
	} else {
		return uint64(idx), uint64(*((*C.Word_t)(pval))), true
	}
}
示例#10
0
文件: judyl.go 项目: riobard/go-judy
// Locate the Nth index that is present in the JudyL array (Nth = 1 returns the first index present).
//
//   nth - nth index to find
//   returns uint64 - nth index (unless return false)
//           uint64 - nth value (unless return false)
//           bool   - true if the search was successful, false if an index was not found
func (j *JudyL) ByCount(nth uint64) (uint64, uint64, bool) {
	var idx C.Word_t
	pval := unsafe.Pointer(C.JudyLByCount(C.Pcvoid_t(j.array), C.Word_t(nth), &idx, nil))

	if pval == nil {
		return 0, 0, false
	} else {
		return uint64(idx), uint64(*((*C.Word_t)(pval))), true
	}
}
示例#11
0
文件: judyl.go 项目: riobard/go-judy
// Count the number of indexes present in the JudyL array between indexA and indexB (inclusive).
// Returns the count. A return value of 0 can be valid as a count, or it can indicate a special case for fully populated array (32-bit machines only). See libjudy docs for ways to resolve this.
func (j *JudyL) CountFrom(indexA, indexB uint64) uint64 {
	return uint64(C.JudyLCount(C.Pcvoid_t(j.array), C.Word_t(indexA), C.Word_t(indexB), nil))
}
示例#12
0
文件: judy1.go 项目: riobard/go-judy
// Test if index's bit is set in the Judy1 array.
// Return true if index's bit is set (index is present), false if it is unset (index is absent).
func (j *Judy1) Test(index uint64) bool {
	return C.Judy1Test(C.Pcvoid_t(j.array), C.Word_t(index), nil) != 0
}
示例#13
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) Count(index1 uint64, index2 uint64) uint64 {
	return uint64(C.Judy1Count(C.Pcvoid_t(j.val), C.Word_t(index1), C.Word_t(index2), nil))
}
示例#14
0
文件: judy1.go 项目: bickfordb/judy
func (j *Judy1) Unset(bit uint64) {
	C.Judy1Unset(C.PPvoid_t(&j.val), C.Word_t(bit), nil)
}
示例#15
0
文件: judy1.go 项目: riobard/go-judy
// Unset index's bit in the Judy1 array.
// Return true if index's bit was previously set (successful), otherwise false if the bit was already unset (unsuccessful).
func (j *Judy1) Unset(index uint64) bool {
	return C.Judy1Unset(C.PPvoid_t(&j.array), C.Word_t(index), nil) != 0
}
示例#16
0
文件: judyl.go 项目: riobard/go-judy
// Delete the Index/Value pair from the JudyL array.
// Returns true if successful. Returns false if Index was not present.
func (j *JudyL) Delete(index uint64) bool {
	return C.JudyLDel(C.PPvoid_t(&j.array), C.Word_t(index), nil) != 0
}
示例#17
0
文件: judyl.go 项目: riobard/go-judy
// Insert an Index and Value into the JudyL array. If the Index is successfully inserted, the Value is
// initialized as well. If the Index was already present, the current Value is replaced with the provided Value.
func (j *JudyL) Insert(index uint64, value uint64) {
	pval := unsafe.Pointer(C.JudyLIns(C.PPvoid_t(&j.array), C.Word_t(index), nil))
	*((*C.Word_t)(pval)) = C.Word_t(value)
}