예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #16
0
 def __init__(self):
     self.a = new_array(1)
     self.size = 0
     self.cap = len(self.a)
     self.front = 0
     self.empty = 0
예제 #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    
예제 #18
0
파일: arrayqueue.py 프로젝트: patmorin/ods
 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)
예제 #20
0
파일: btree.py 프로젝트: rugbyprof/ods
 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)
예제 #21
0
 def _initialize(self):
     self.adj = new_array(self.n)
     for i in range(self.n):
         self.adj[i] = ArrayStack()
예제 #22
0
 def initialize(self):
     self.d = 1
     self.t = new_array((1 << self.d))
     self.q = 0
     self.n = 0
예제 #23
0
 def grow(self):
     self.blocks.append(new_array(self.blocks.size() + 1))
예제 #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)
예제 #25
0
 def _initialize(self):
     self.adj = new_array(self.n)
     for i in range(self.n):
         self.adj[i] = ArrayStack()
예제 #26
0
def dfs(g, r):
    c = new_array(g.n)
    _dfs(g, r, c)
예제 #27
0
 def __init__(self, x, h):
     self.x = x
     self.next = new_array(h+1)
예제 #28
0
 def __init__(self):
     self.child  = new_array(2)
     self.jump = None
     self.parent = None
     self.x = None
예제 #29
0
 def __init__(self, b):
     super(SEList.BDeque, self).__init__()
     self.a = new_array(b + 1)
예제 #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
예제 #31
0
 def __init__(self, x, h):
     self.x = x
     self.next = new_array(h+1)
     self.length = numpy.ones(h+1, dtype=int)
예제 #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)
예제 #33
0
 def _initialize(self):
     self.a = new_array(1)
     self.j = 0
     self.n = 0
예제 #34
0
파일: arrayqueue.py 프로젝트: patmorin/ods
 def _initialize(self):
     self.a = new_array(1)
     self.j = 0
     self.n = 0
예제 #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
예제 #36
0
 def grow(self):
     self.blocks.append(new_array(self.blocks.size()+1))
예제 #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
예제 #38
0
 def __init__(self):
     self.a = new_array(1)
     self.n = 0
     self.capacity = len(self.a)
예제 #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)
예제 #41
0
 def __init__(self):
     self.child = new_array(2)
     self.jump = None
     self.parent = None
     self.x = None
예제 #42
0
파일: selist.py 프로젝트: rugbyprof/ods
 def __init__(self, b):
     super(SEList.BDeque, self).__init__()
     self.a = new_array(b+1)
예제 #43
0
 def initialize(self):
     self.d = 1
     self.t = new_array((1<<self.d))
     self.q = 0
     self.n = 0
예제 #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
예제 #45
0
파일: arraystack.py 프로젝트: rugbyprof/ods
 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