-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0f60c32
Showing
6 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo, bar, txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo, bar, txt |