Beispiel #1
0
	def __init__(self, size):
		self.prim_keys = Array.Array(size)
		self.prim_values = Array.Array(size)
		self.ovflw_keys = Array.Array(size)
		self.ovflw_values = Array.Array(size)
		self.resizing = True                            # two different versions of the program, one resizes and the other does not
		self.debugging = False
Beispiel #2
0
	def clear(self):
		self.prim_keys = Array.Array(size)
		self.prim_values = Array.Array(size)
		self.ovflw_keys = Array.Array(size)
		self.ovflw_values = Array.Array(size)

		
		
		
Beispiel #3
0
 def __init__(self, size):
     ''' Creates two different versions of the program:
         one resizes, and the other does not.
     '''
     self.size = size
     self.prim_keys = Array.Array(size)
     self.prim_values = Array.Array(size)
     self.ovflw_keys = Array.Array(size)
     self.ovflw_values = Array.Array(size)
     self.resizing = True 
     self.debugging = False
Beispiel #4
0
    def _resize(self):
        '''
        Private method that doubles the size of the overflow array
        if there are no more None spots left. Copies the key/value pairs
        to the larger overflow array, again in sequential position.
        '''
        temp_keys = Array.Array(len(self.overflow_keys) * 2)
        temp_values = Array.Array(len(self.overflow_keys) * 2)
        for i in range(len(self.overflow_values)):
            temp_keys[i] = self.overflow_keys[i]
            temp_values[i] = self.overflow_values[i]

        self.overflow_keys = temp_keys
        self.overflow_values = temp_values
        return
Beispiel #5
0
def radisSort(intList, numDigits):
	# Create an array of queues to represent the bins
	NUM_BINS = 10

	binArray = Array(NUM_BINS)
	for k in range(NUM_BINS):
		binArray[k] = Queue()

	# The value of the current column
	column = 1

	# Iterate over the number of digits in the larges value
	for d in range(numDigits):

		# Distribute the keys accross the 10 bins
		for key in intList:
			digit = (key // column) % NUM_BINS
			binArray[digit].enqueue(key)

		# Gather the keys from the bins and place them back in intList
		i = 0
		for bin in binArray:
			while not bin.isEmpty():
				intList[i] = bin.dequeue()
				i += 1

		# Advance to the next column value
		column *= NUM_BINS
Beispiel #6
0
def main():
    t = Tree.Average('tree.xml')
    print(t.serchAver())

    a = Array.Array()
    print(a.draw())
    print(a.separate())
Beispiel #7
0
 def rehash(self):
     if self.loadFactor() > 0.5:
         items = list(self)
         self._items = Array(len(self._items) * 2)
         self._size = 0
         for item in items:
             self.add(item)
Beispiel #8
0
	def __init__(self, size):
		'''
			self.size is the size of the array
			self.primaryKeys is the array of the primary area values
			self.overflowKeys is the array of the overflow area values
			self.primaryValues is the array of the values of the primary area
			self.overflowValues is the array of the values of the overflow area
			self.debug is if debuging is on or off. It's off by default
		'''
		self.size = size
		self.primaryKeys = Array(self.size)
		self.primaryValues = Array(self.size)
		self.overflowKeys = Array(self.size)
		self.overflowValues = Array(self.size)
		self._debug = False
		self.resizing = True
Beispiel #9
0
 def __init__(self, sourceCollection = None, capacity = None):
     if capacity == None:
         self._capacity = HashSet.DEFAULT_CAPACITY
     else:
         self._capacity = capacity
     self._items = Array(self._capacity)         # 集的条目
     self._foundNode = self._priorNode = None    # 引用要定位的节点,否则为None,引用定位的节点之前的节点,否则为None
     self._index = -1                            # 引用节点所在链的索引,否则置为-1
     AbstractCollection.__init__(self, sourceCollection)
Beispiel #10
0
	def tabulate(self):
		self.belowcount = 0           # this counts values below the starting value
		self.abovecount = 0           # this counts values above the ending value
		numslots = int(round((self.end - self.start)/self.delta, 0))
		self.counts = Array.Array(numslots, 0)
		for line in self.lines:
			n = float(line)
			if n < self.start:
				self.belowcount += 1
			elif n > self.end:
				self.abovecount += 1
			else:
				slotnumber = int((n - self.start) / self.delta)
				self.counts[slotnumber] += 1
Beispiel #11
0
 def __init__(self, size=10):
     self.array = Array(size)
     self.max = size
     self.numused = 0
     self.tree = BST()
     self.debug = False
Beispiel #12
0
 def clear(self):
     self._items = Array(self._capacity)
     self._size = 0
Beispiel #13
0
 def __init__(self, capacity=10):
     self.__array = Array.Array(capacity)
Beispiel #14
0
def test_string():
    assert isinstance(a.Array(shape, 1, 2, 3).__str__(), str) == True
Beispiel #15
0
"""
Tests are parametrized
Tests are mostly for 1D and 2D, an aditional 3D addition test is included to test functionality
Array class was constructed directly with multidimentional support, and tests for 2D used to test
the functionality, since the logic follows for all higher dimentional arrays
"""


def test_string():
    assert isinstance(a.Array(shape, 1, 2, 3).__str__(), str) == True


@pytest.mark.parametrize(
    "arg, expected_output",
    [
        [(a.Array(shape, 3, 2, 5), a.Array(shape, 3, 2, 1)), [6, 4, 6]],
        [(a.Array(shape, 4, 2, 2), a.Array(shape, 2, 1, 3)), [6, 3, 5]],
        [(a.Array(shape, 6, 6, 7), a.Array(shape, 4, 0, 2)), [10, 6, 9]],
        [(a.Array(shape2, 4, 2, 2, 2), a.Array(shape2, 1, 2, 1, 3)), [[5, 4], [3, 5]]],
        [(a.Array(shape2, 6, 6, 7, 3), a.Array(shape2, 1, 4, 0, 2)), [[7, 10], [7, 5]]],
        [
            (
                a.Array(shape3, 1, 2, 3, 2, 1, 2, 3, 2, 1),
                a.Array(shape3, 3, 2, 1, 4, 3, 2, 1, 3, 2),
            ),
            [[4, 4, 4], [6, 4, 4], [4, 5, 3]],
        ],
    ],
)
def test_add(arg, expected_output):
    assert arg[0] + arg[1] == expected_output
Beispiel #16
0
 def __init__(self, size, debug=False):
     self.prim_keys = Array.Array(size)
     self.prim_values = Array.Array(size)
     self.overflow_keys = Array.Array(size)
     self.overflow_values = Array.Array(size)
     self._debug = debug
Beispiel #17
0
from Array import *

ARRAY_SIZE = 10

array = Array(ARRAY_SIZE)
for i in range(array.len()):
    array.setitem(i, i * 2)

for i in range(array.len()):
    value = array.getitem(i)
    if value == i * 2:
        print(value),
    else:
        print("Error on index %d, the error value is %d" % (i, value))
Beispiel #18
0
import Array

def reversingArray(start, end, myArray):
    while start < end:
        myArray[start], myArray[end - 1] = myArray[end - 1], myArray[start]
        start += 1
        end -= 1

if __name__ == '__main__':
    myArray = Array.Array(10)
    myArray.insert(2, 2)
    myArray.insert(1, 3)
    myArray.insert(3, 1)
    print('Array before reversing:', myArray.__str__())
    reversingArray(0, len(myArray), myArray)
    print('Array after reversing:', myArray.__str__())
Beispiel #19
0
 def clear(self):
     self._size = 0
     self._items = Array(ArrayList.DEFAULT_CAPACITY)
Beispiel #20
0
 def __init__(self, sourceCollection = None):
     self._items = Array(ArrayList.DEFAULT_CAPACITY)
     AbstractList.__init__(self, sourceCollection)
Beispiel #21
0
import Array

matriz = Array.Array()
matriz1 = Array.Array()

matriz.addToArray2x3(1, 2, 3, 4, 5, 6)

print(matriz.getArray())
print('')

print(matriz.stdOfValues())
print('')

matriz1.arrayOfEye(4)

print(matriz1.getArray())
Beispiel #22
0
	def clear(self):
		self.primaryKeys = Array(size)
		self.primaryValues = Array(size)
		self.overflowKeys = Array(size)
		self.overflowValues = Array(size)