Skip to content

Commit

Permalink
Adding registers calculating size of register. Missing dynamic alloca…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
marciovicente committed May 14, 2014
1 parent 99b7968 commit 6879482
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
binary
test.*
*.dat
Binary file removed binary
Binary file not shown.
69 changes: 50 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Universidade Federal da Bahia
# Estrutura de Dados e Algoritmos II
# Author: @marciovicente
# Author: @marciovicente
# Email: [email protected]


import sys, struct
import sys, struct, os, pickle
sys.path.insert(0, 'libs/')

# TODO - Change another name to Appliocation class
Expand All @@ -19,6 +19,7 @@ def __init__(self):
self.value = None
self.sequence = None
self.age = None
self.index = None
super(Node, self).__init__()


Expand All @@ -28,33 +29,52 @@ class Application(object):
def __init__(self):
self.method = None
self.file = None
self.filename = 'binary'
self.filename = 'lisch.dat'
self.SIZE_OF_FILE = 11
super(Application, self).__init__()

def init_file(self):
n = Node()
n.method = n.value = n.sequence = n.age = n.index = ''
dumpped = pickle.dumps(n)
obj_size = sys.getsizeof(dumpped)
self.file.seek(self.SIZE_OF_FILE * obj_size)
self.close_file()

def main(self):
method = raw_input()
self.filename = 'lisch.dat' if method == 'l' else 'eisch.dat'
self.open_file()
self.init_file()

operation = raw_input()
if operation == 'i':
self.insert_record()
elif operation == 'c':
self.query()
elif operation != 'e':
return
while operation != 'e':
if operation == 'i':
self.insert_record()
elif operation == 'c':
self.query()
operation = raw_input()
return

def mod(self, n):
return n % self.SIZE_OF_FILE

def solve_colision(self):
pass

def point_to_value(self, value):
""" This method point to index in file """
""" This method point to index in a file """

value = int(value)
index = self.mod(value)
self.file.seek(index)
length = 211 if index > 1 else 1 # TODO - Change 211 to global dynamic variable
self.file.seek(index * length)

def insert_record(self):
# if os.path.getsize(self.filename) >= self.SIZE_OF_FILE:
# print 'Arquivo cheio'
self.open_file()

value = raw_input()
sequence = raw_input()
age = raw_input()
Expand All @@ -65,19 +85,30 @@ def insert_record(self):

if self.file:
self.point_to_value(n.value)
if self.file.read(): # ie, if has colision
if self.file.read() != '': # ie, if has colision
print 'chave ja existente: %s' % n.value
self.solve_colision()
else:
self.file.write(str(n.value))
self.file.write(pickle.dumps(n))
self.close_file()

def query(self):
self.open_file()
obj = None
value = raw_input()
self.point_to_value(value)
if self.file.read():
print 'chave: %s' % value
print 'self.sequence'
print 'self.age'

# TODO, Implements when the position doesn't exist
try:
obj = pickle.loads(self.file.read())
except IOError:
print u'chave não encontrada: %s' % value
return

if obj:
print 'chave: %s' % obj.value
print 'self.sequence: %s' % obj.sequence
print 'self.age %s' % obj.age

def open_file(self):
self.file = open(self.filename, 'rb+')
Expand Down
1 change: 0 additions & 1 deletion test.bat

This file was deleted.

1 change: 0 additions & 1 deletion test.txt

This file was deleted.

0 comments on commit 6879482

Please sign in to comment.