Example #1
0
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
}
Example #2
0
// 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
	}
}
Example #3
0
// 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
	}
}
Example #4
0
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
}
Example #5
0
// 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
	}
}
Example #6
0
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
}
Example #7
0
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
}
Example #8
0
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
}
Example #9
0
// 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
	}
}
Example #10
0
// 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
	}
}
Example #11
0
// 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))
}
Example #12
0
// 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
}
Example #13
0
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))
}
Example #14
0
func (j *Judy1) Unset(bit uint64) {
	C.Judy1Unset(C.PPvoid_t(&j.val), C.Word_t(bit), nil)
}
Example #15
0
// 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
}
Example #16
0
// 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
}
Example #17
0
// 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)
}