SparseArray
from panda3d.core import SparseArray
- class SparseArray
Bases:
This class records a set of integers, where each integer is either present or not present in the set.
It is similar in principle and in interface to a
BitArray
(which can be thought of as a set of integers, one integer corresponding to each different bit position), but the SparseArray is implemented as a list of min/max subrange lists, rather than as a bitmask.This makes it particularly efficient for storing sets which consist of large sections of consecutively included or consecutively excluded elements, with arbitrarily large integers, but particularly inefficient for doing boolean operations such as & or |.
Also, unlike
BitArray
, the SparseArray can store negative integers.Inheritance diagram
- __and__(other: SparseArray) SparseArray
- __eq__(other: SparseArray) bool
- __iand__(other: SparseArray) SparseArray
- __ilshift__(shift: int) SparseArray
- __init__()
- __init__(from: BitArray)
- __init__(param0: SparseArray)
- __ior__(other: SparseArray) SparseArray
- __irshift__(shift: int) SparseArray
- __ixor__(other: SparseArray) SparseArray
- __lt__(other: SparseArray) bool
- __ne__(other: SparseArray) bool
- __or__(other: SparseArray) SparseArray
- __rshift__(shift: int) SparseArray
- __xor__(other: SparseArray) SparseArray
- static allOff() SparseArray
Returns a
SparseArray
whose bits are all off.
- static allOn() SparseArray
Returns a
SparseArray
with an infinite array of bits, all on.
- static bit(index: int) SparseArray
Returns a
SparseArray
with only the indicated bit on.
- clear()
Sets all the bits in the
SparseArray
off.
- clearBit(index: int)
Sets the nth bit off. If n >=
getNumBits()
, this automatically extends the array.
- compareTo(other: SparseArray) int
Returns a number less than zero if this
SparseArray
sorts before the indicated otherSparseArray
, greater than zero if it sorts after, or 0 if they are equivalent. This is based on the same ordering defined by operator <.
- getBit(index: int) bool
Returns true if the nth bit is set, false if it is cleared. It is valid for n to increase beyond
getNumBits()
, but the return valuegetNumBits()
will always be the same.
- static getClassType() TypeHandle
- getHighestBits() bool
Returns true if the infinite set of bits beyond
getNumBits()
are all on, or false of they are all off.
- getHighestOffBit() int
Returns the index of the highest 0 bit in the array. Returns -1 if there are no 0 bits or if there an infinite number of 1 bits.
- getHighestOnBit() int
Returns the index of the highest 1 bit in the array. Returns -1 if there are no 1 bits or if there an infinite number of 1 bits.
- getLowestOffBit() int
Returns the index of the lowest 0 bit in the array. Returns -1 if there are no 0 bits or if there are an infinite number of 1 bits.
- getLowestOnBit() int
Returns the index of the lowest 1 bit in the array. Returns -1 if there are no 1 bits or if there are an infinite number of 1 bits.
- static getMaxNumBits() int
If
getMaxNumBits()
returned true, this method may be called to return the maximum number of bits that may be stored in this structure. It is an error to call this ifgetMaxNumBits()
return false.It is always an error to call this method. The
SparseArray
has no maximum number of bits. This method is defined so generic programming algorithms can use BitMask orSparseArray
interchangeably.
- getNextHigherDifferentBit(low_bit: int) int
Returns the index of the next bit in the array, above low_bit, whose value is different that the value of low_bit. Returns low_bit again if all bits higher than low_bit have the same value.
This can be used to quickly iterate through all of the bits in the array.
- getNumBits() int
Returns the current number of possibly different bits in this array. There are actually an infinite number of bits, but every bit higher than this bit will have the same value, either 0 or 1 (see
getHighestBits()
).This number may grow and/or shrink automatically as needed.
- getNumOffBits() int
Returns the number of bits that are set to 0 in the array. Returns -1 if there are an infinite number of 0 bits.
- getNumOnBits() int
Returns the number of bits that are set to 1 in the array. Returns -1 if there are an infinite number of 1 bits.
- getNumSubranges() int
Returns the number of separate subranges stored in the
SparseArray
. You can use this limit to iterate through the subranges, callinggetSubrangeBegin()
andgetSubrangeEnd()
for each one.Also see
isInverse()
.
- getSubrangeBegin(n: int) int
Returns the first numeric element in the nth subrange.
Also see
isInverse()
.
- getSubrangeEnd(n: int) int
Returns the last numeric element, plus one, in the nth subrange.
Also see
isInverse()
.
- hasAllOf(low_bit: int, size: int) bool
Returns true if all bits in the indicated range are set, false otherwise.
- hasAnyOf(low_bit: int, size: int) bool
Returns true if any bit in the indicated range is set, false otherwise.
- hasBitsInCommon(other: SparseArray) bool
Returns true if this
SparseArray
has any “one” bits in common with the other one, false otherwise.This is equivalent to (array & other) != 0, but may be faster.
- static hasMaxNumBits() bool
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise. If this returns true, the number may be queried in
getMaxNumBits()
.This method always returns false. The
SparseArray
has no maximum number of bits. This method is defined so generic programming algorithms can use BitMask orSparseArray
interchangeably.
- invertInPlace()
Inverts all the bits in the
SparseArray
. This is equivalent to array = ~array.
- isInverse() bool
If this is true, the
SparseArray
is actually defined as a list of subranges of integers that are not in the set. If this is false (the default), then the subranges define the integers that are in the set. This affects the interpretation of the values returned by iterating throughgetNumSubranges()
.
- static lowerOn(on_bits: int) SparseArray
Returns a
SparseArray
whose lower on_bits bits are on.
- operator(shift: int) SparseArray
- operator(shift: int) SparseArray
- static range(low_bit: int, size: int) SparseArray
Returns a
SparseArray
whose size bits, beginning at low_bit, are on.
- setBit(index: int)
Sets the nth bit on. If n >=
getNumBits()
, this automatically extends the array.