private void TryExpandSize(int key) { if (key >= data.Capacity) { data.Capacity = GMath.Max(data.Capacity * 2, key + 1); } for (int i = 0; i < key - Count + 1; i++) { data.Add(null); } }
public float Sum(int range) { float sum = 0; int treeInd = range + 1; while (treeInd > 0) { sum += tree[treeInd]; treeInd -= GMath.LowBit(treeInd); } return(sum); }
public virtual bool RemoveByInd(int key) { if (IsFree(key)) { return(false); } T old = data[key]; data[key] = null; RemoveUsedKey(key); _freeRow = GMath.Min(key, _freeRow); if (OnDel != null) { OnDel(key, old); } return(true); }
public void Set(int index, float num) { float delta = num; if (index >= Count) { throw new Exception("[NumberTree Set] argument out of range"); } else { delta = num - values[index]; } int treeInd = index + 1; while (treeInd < TreeCount) { tree[treeInd] += num; treeInd += GMath.LowBit(treeInd); } }