def _resize(self, cap): #Resize the Array list b = new_array(cap) for i in range(self.size): b[i] = self.a[(self.front + i) % self.size] self.a = b self.cap = cap self.front = 0
def __init__(self): super(XFastTrie, self).__init__() self.nil = self._new_node() self.t = new_array(w + 1) for i in range(w + 1): self.t[i] = LinearHashTable() self.t[0].add(self.r)
def dfs2(g, r): c = new_array(g.n) s = SLList() s.push(r) while s.size() > 0: i = s.pop() if c[i] == white: c[i] = grey for j in g.out_edges(i): s.push(j)
def counting_sort(a, k): c = new_zero_array(k) for i in range(len(a)): c[a[i]] += 1 for i in range(1, k): c[i] += c[i - 1] b = new_array(len(a)) for i in range(len(a) - 1, -1, -1): c[a[i]] -= 1 b[c[a[i]]] = a[i] return b
def counting_sort(a, k): c = new_zero_array(k) for i in range(len(a)): c[a[i]] += 1 for i in range(1, k): c[i] += c[i-1] b = new_array(len(a)) for i in range(len(a)-1, -1, -1): c[a[i]] -= 1 b[c[a[i]]] = a[i] return b
def resize(self, capacity, k, value): b = new_array(capacity) #New array created index = 0 #the index is tracked for i in range(self.n + 1): if i == k: #k is is specified index, adds an element b[i] = value else: b[i] = self.a[index] index += 1 self.a = b self.capacity = capacity
def _resize(self): self.d = 1 while ((1<<self.d) < 3*self.n): self.d += 1 told = self.t self.t = new_array((1<<self.d)) self.q = self.n for x in told: if x is not None and x != self.dl: i = self._hash(x) while self.t[i] is not None: i = (i+1) % len(self.t) self.t[i] = x
def _resize(self): self.d = 1 while ((1 << self.d) < 3 * self.n): self.d += 1 told = self.t self.t = new_array((1 << self.d)) self.q = self.n for x in told: if x is not None and x != self.dl: i = self._hash(x) while self.t[i] is not None: i = (i + 1) % len(self.t) self.t[i] = x
def rebuild(self, u): ns = self._size(u) p = u.parent a = new_array(ns) self.pack_into_array(u, a, 0) if p == self.nil: self.r = self.build_balanced(a, 0, ns) self.r.parent = nil elif p.right == u: p.right = self.build_balanced(a, 0, ns) p.right.parent = p else: p.left = self.build_balanced(a, 0, ns) p.left.parent = p
def radix_sort(a): for p in range(w//d): c = new_zero_array(1<<d) b = new_array(len(a)) for i in range(len(a)): bits = (a[i] >> d*p)&((1<<d)-1) c[bits] += 1 for i in range(1, 1<<d): c[i] += c[i-1] for i in range(len(a)-1, -1, -1): bits = (a[i] >> d*p)&((1<<d)-1) c[bits] -=1 b[c[bits]] = a[i] a = b return b
def radix_sort(a): for p in range(w // d): c = new_zero_array(1 << d) b = new_array(len(a)) for i in range(len(a)): bits = (a[i] >> d * p) & ((1 << d) - 1) c[bits] += 1 for i in range(1, 1 << d): c[i] += c[i - 1] for i in range(len(a) - 1, -1, -1): bits = (a[i] >> d * p) & ((1 << d) - 1) c[bits] -= 1 b[c[bits]] = a[i] a = b return b
def _resize(self): b = new_array(max(1, 2*self.n)) b[0:self.n] = self.a[0:self.n] self.a = b
def resize(self, capacity): b = new_array(capacity) for i in range(self.n): b[i] = self.a[i] self.a = b self.capacity = capacity
def __init__(self): self.a = new_array(1) self.size = 0 self.cap = len(self.a) self.front = 0 self.empty = 0
def resize(self): b = new_array(max(2*self.n, 1)) for i in range(self.n): b[i] = self.a[i] self.a = b
def _resize(self): b = new_array(max(1, 2*self.n)) for k in range(self.n): b[k] = self.a[(self.j+k) % len(self.a)] self.a = b self.j = 0
def __init__(self, x, h): self.x = x self.next = new_array(h+1) self.length = numpy.ones(h+1, dtype=int)
def __init__(self, btree): self.btree = btree self.keys = new_array(self.btree.b) self.children = new_int_array(self.btree.b+1, -1) self.id = self.btree.bs.place_block(self)
def _initialize(self): self.adj = new_array(self.n) for i in range(self.n): self.adj[i] = ArrayStack()
def initialize(self): self.d = 1 self.t = new_array((1 << self.d)) self.q = 0 self.n = 0
def grow(self): self.blocks.append(new_array(self.blocks.size() + 1))
def __init__(self, btree): self.btree = btree self.keys = new_array(self.btree.b) self.children = new_int_array(self.btree.b + 1, -1) self.id = self.btree.bs.place_block(self)
def dfs(g, r): c = new_array(g.n) _dfs(g, r, c)
def __init__(self, x, h): self.x = x self.next = new_array(h+1)
def __init__(self): self.child = new_array(2) self.jump = None self.parent = None self.x = None
def __init__(self, b): super(SEList.BDeque, self).__init__() self.a = new_array(b + 1)
def _resize(self): b = new_array(max(1, 2 * self.n)) b[0:self.n] = self.a[0:self.n] self.a = b
def _initialize(self): self.h = 0 self.n = 0 self.sentinel = self._new_node(None, 32) self.stack = new_array(self.sentinel.height()+1)
def _initialize(self): self.a = new_array(1) self.j = 0 self.n = 0
def __init__(self): self.a = new_array(1) #New array is created self.n = 0 #Number of elements in the array self.capacity = len(self.a) #The capacity of the array
def grow(self): self.blocks.append(new_array(self.blocks.size()+1))
def resize(self): b = new_array(max(2 * self.n, 1)) for i in range(self.n): b[i] = self.a[i] self.a = b
def __init__(self): self.a = new_array(1) self.n = 0 self.capacity = len(self.a)
def __init__(self, b): super(SEList.BDeque, self).__init__() self.a = new_array(b+1)
def initialize(self): self.d = 1 self.t = new_array((1<<self.d)) self.q = 0 self.n = 0
def _resize(self): b = new_array(max(1, 2 * self.n)) for k in range(self.n): b[k] = self.a[(self.j + k) % len(self.a)] self.a = b self.j = 0
def _resize(self): b = new_array(max(1, 2 * self.n)) for i in range(self.n): b[i] = self.a[i] self.a = b