Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marciovicente committed May 13, 2014
0 parents commit 0f60c32
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
Empty file added __init__.py
Empty file.
Binary file added binary
Binary file not shown.
Binary file added libs/scanf.pyc
Binary file not shown.
88 changes: 88 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/python

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


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

# TODO - Change another name to Appliocation class
# because this must be a node of list, and not an application

class Application(object):
""" Application Class """

def __init__(self):
self.method = None
self.value = None
self.sequence = None
self.age = None
self.file = None
self.filename = 'binary'
self.SIZE_OF_FILE = 11
super(Application, self).__init__()

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

# UNUSED
def get_entries(self):
self.value = raw_input()
self.sequence = raw_input()
self.age = raw_input()

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 """
value = int(value)
index = self.mod(value)
self.file.seek(index)

def insert_record(self):
self.value = raw_input()
self.sequence = raw_input()
self.age = raw_input()

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

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

def open_file(self):
self.file = open(self.filename, 'rb+')

def close_file(self):
if self.file:
self.file.close()



app = Application()
app.main()

1 change: 1 addition & 0 deletions test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo, bar, txt
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo, bar, txt

0 comments on commit 0f60c32

Please sign in to comment.