Example #1
0
 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
Example #2
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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
Example #6
0
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
Example #7
0
 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
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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
Example #12
0
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
Example #13
0
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
Example #14
0
 def _resize(self):
     b = new_array(max(1, 2*self.n))
     b[0:self.n] = self.a[0:self.n]
     self.a = b
Example #15
0
 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
Example #16
0
 def __init__(self):
     self.a = new_array(1)
     self.size = 0
     self.cap = len(self.a)
     self.front = 0
     self.empty = 0
Example #17
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    
Example #18
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 __init__(self, x, h):
     self.x = x
     self.next = new_array(h+1)
     self.length = numpy.ones(h+1, dtype=int)
Example #20
0
 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)
Example #21
0
 def _initialize(self):
     self.adj = new_array(self.n)
     for i in range(self.n):
         self.adj[i] = ArrayStack()
Example #22
0
 def initialize(self):
     self.d = 1
     self.t = new_array((1 << self.d))
     self.q = 0
     self.n = 0
Example #23
0
 def grow(self):
     self.blocks.append(new_array(self.blocks.size() + 1))
Example #24
0
 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)
Example #25
0
 def _initialize(self):
     self.adj = new_array(self.n)
     for i in range(self.n):
         self.adj[i] = ArrayStack()
Example #26
0
def dfs(g, r):
    c = new_array(g.n)
    _dfs(g, r, c)
Example #27
0
 def __init__(self, x, h):
     self.x = x
     self.next = new_array(h+1)
Example #28
0
 def __init__(self):
     self.child  = new_array(2)
     self.jump = None
     self.parent = None
     self.x = None
Example #29
0
 def __init__(self, b):
     super(SEList.BDeque, self).__init__()
     self.a = new_array(b + 1)
Example #30
0
 def _resize(self):
     b = new_array(max(1, 2 * self.n))
     b[0:self.n] = self.a[0:self.n]
     self.a = b
Example #31
0
 def __init__(self, x, h):
     self.x = x
     self.next = new_array(h+1)
     self.length = numpy.ones(h+1, dtype=int)
Example #32
0
 def _initialize(self):
     self.h = 0
     self.n = 0
     self.sentinel = self._new_node(None, 32)
     self.stack = new_array(self.sentinel.height()+1)
Example #33
0
 def _initialize(self):
     self.a = new_array(1)
     self.j = 0
     self.n = 0
Example #34
0
 def _initialize(self):
     self.a = new_array(1)
     self.j = 0
     self.n = 0
Example #35
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
Example #36
0
 def grow(self):
     self.blocks.append(new_array(self.blocks.size()+1))
Example #37
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
Example #38
0
 def __init__(self):
     self.a = new_array(1)
     self.n = 0
     self.capacity = len(self.a)
Example #39
0
def dfs(g, r):
    c = new_array(g.n)
    _dfs(g, r, c)
 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 __init__(self):
     self.child = new_array(2)
     self.jump = None
     self.parent = None
     self.x = None
Example #42
0
 def __init__(self, b):
     super(SEList.BDeque, self).__init__()
     self.a = new_array(b+1)
Example #43
0
 def initialize(self):
     self.d = 1
     self.t = new_array((1<<self.d))
     self.q = 0
     self.n = 0
Example #44
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
Example #45
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