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 }
// 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 } }
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 }
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 }
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 }
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 }
// 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 } }
// 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 } }
// 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 } }
// 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 } }
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)) }
// Return the number of bytes of memory currently in use by JudyL array. This is a very fast routine, // and may be used with little performance impact. func (j *JudyL) MemoryUsed() uint64 { return uint64(C.JudyLMemUsed(C.Pcvoid_t(j.array))) }
// 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)) }
// Count the number of indexes present in the JudyL array. // 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) CountAll() uint64 { return uint64(C.JudyLCount(C.Pcvoid_t(j.array), 0, math.MaxUint64, nil)) }
// 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 }