mirror of
https://github.com/originalmk/natural-merge-sort.git
synced 2025-01-18 08:19:18 +00:00
Changed commands names to English
This commit is contained in:
parent
06eeaef7f3
commit
3a4476299f
29
README.md
29
README.md
@ -20,26 +20,29 @@ A > B if after removing all common records from A and B, maximum number from A i
|
|||||||
3. Check if series counter is 1 and if not then go back to step 1.
|
3. Check if series counter is 1 and if not then go back to step 1.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
Currently all commands are named using Polish words, but it will be changed soon.
|
- help
|
||||||
- pomoc
|
|
||||||
- displays the help page
|
- displays the help page
|
||||||
- wyczyść <path_to_tape>
|
- clear <path_to_tape>
|
||||||
- clears/deletes a tape
|
- clears/deletes a tape
|
||||||
- Example: wyczyść fs/t1
|
- Example: clear fs/t1
|
||||||
- genlos <path_to_tape> <record_count> [options]
|
- genrandom <path_to_tape> <record_count> [options]
|
||||||
- adds record_count random records at the end of the tape
|
- adds record_count random records at the end of the tape
|
||||||
- if 'o' is provided as an option then tape is overwritten with these newly generated random records
|
- if 'o' is provided as an option then tape is overwritten with these newly generated random records
|
||||||
- Example: genlos fs/t1 30 o
|
- Example: genrandom fs/t1 30 o
|
||||||
- wczytaj <path_to_tape> <path_to_test_file>
|
- add <path_to_tape> <numbers, ...>
|
||||||
|
- adds new record (set created from 1 to 15 numbers in range 0-255) at the
|
||||||
|
end of the tape
|
||||||
|
- Example: add fs/t1 7 25 3 4 5
|
||||||
|
- load <path_to_tape> <path_to_test_file>
|
||||||
- adds the records described in test file to the tape
|
- adds the records described in test file to the tape
|
||||||
- Example: wczytaj fs/t1 fs/testfile
|
- Example: load fs/t1 fs/testfile
|
||||||
- sortuj <path_to_tape> [options]
|
- sort <path_to_tape> [options]
|
||||||
- sorts the provided tape displaying its contents before and after sorting. When option 'v' is provided then tape will be displayed after each phase
|
- sorts the provided tape displaying its contents before and after sorting. When option 'v' is provided then tape will be displayed after each phase
|
||||||
- Example: sortuj fs/t1 v
|
- Example: sort fs/t1 v
|
||||||
- wyświetl <path_to_tape>
|
- display <path_to_tape>
|
||||||
- displays the tape's records and information how many series and records it contains. Also when displaying records it is shown when each of series end
|
- displays the tape's records and information how many series and records it contains. Also when displaying records it is shown when each of series end
|
||||||
- Example: wyświetl fs/t1
|
- Example: display fs/t1
|
||||||
- wyjście
|
- exit
|
||||||
- exists program gracefully
|
- exists program gracefully
|
||||||
|
|
||||||
## Test file format
|
## Test file format
|
||||||
|
116
naturalmerge.py
116
naturalmerge.py
@ -138,7 +138,7 @@ class Record:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Zbiór {sorted(self.items, reverse=True)}"
|
return f"Set {sorted(self.items, reverse=True)}"
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if other is None:
|
if other is None:
|
||||||
@ -195,7 +195,7 @@ class RunIterator:
|
|||||||
|
|
||||||
|
|
||||||
def print_tape(file_name):
|
def print_tape(file_name):
|
||||||
print(f"[ .. ] Taśma {file_name}\n")
|
print(f"[ .. ] Tape {file_name}\n")
|
||||||
|
|
||||||
buffer = ReadBuffer(file_name)
|
buffer = ReadBuffer(file_name)
|
||||||
series_count = 0
|
series_count = 0
|
||||||
@ -207,10 +207,10 @@ def print_tape(file_name):
|
|||||||
print(record)
|
print(record)
|
||||||
records_count += 1
|
records_count += 1
|
||||||
series_count += 1
|
series_count += 1
|
||||||
print("~ koniec biegu ~")
|
print("~ series end ~")
|
||||||
|
|
||||||
print(f"\n[ ^- ] Liczba biegów: {series_count}")
|
print(f"\n[ ^- ] Series count: {series_count}")
|
||||||
print(f"[ ^- ] Liczba rekordów: {records_count}")
|
print(f"[ ^- ] Records count: {records_count}")
|
||||||
|
|
||||||
|
|
||||||
def print_runs(file_name, n):
|
def print_runs(file_name, n):
|
||||||
@ -359,53 +359,53 @@ def tape_sort(tape_path, print_after_phase=False):
|
|||||||
writes_count += merge_info.writes_count
|
writes_count += merge_info.writes_count
|
||||||
|
|
||||||
if print_after_phase:
|
if print_after_phase:
|
||||||
print(f"[ -v ] Faza {phases_count + 1}")
|
print(f"[ -v ] Phase {phases_count + 1}")
|
||||||
print_tape(tape_path)
|
print_tape(tape_path)
|
||||||
print(f"[ .. ] {runs_written} biegów pozostało")
|
print(f"[ .. ] {runs_written} series remaining")
|
||||||
phases_count += 1
|
phases_count += 1
|
||||||
|
|
||||||
return SortInfo(reads_count, writes_count, phases_count)
|
return SortInfo(reads_count, writes_count, phases_count)
|
||||||
|
|
||||||
help_page = """
|
help_page = """
|
||||||
pomoc
|
help
|
||||||
wyświetla tę stronę
|
displays the help page
|
||||||
wyczyść <ścieżka_do_taśmy>
|
clear <tape_path>
|
||||||
usuwa taśmę
|
clears (removes) the tape
|
||||||
genlos <ścieżka_do_taśmy> <liczba_rekordów> [opcje]
|
genrandom <path_to_tape> <records_count> [options]
|
||||||
dopisuje losowo wygenerowane rekordy na taśmę
|
adds record_count random records at the end of the tape
|
||||||
jeżeli jako opcja podane zostanie 'o', wówczas taśma zostanie nadpisana
|
if 'o' is provided as an option then tape is overwritten with these
|
||||||
nowowygenerowanymi rekordami
|
newly generated random records
|
||||||
dopisz <ścieżka_do_taśmy> <liczba, ...>
|
add <path_to_tape> <numbers, ...>
|
||||||
dopisuje nowy rekord na koniec taśmy, jako
|
adds new record (set created from 1 to 15 numbers provided in range 0-255)
|
||||||
<liczba, ...> należy podać co najmniej 1 liczbę, a
|
at the end of the tape
|
||||||
maksymalnie 15, każdą z zakresu 0-255
|
load <path_to_tape> <path_to_test_file>
|
||||||
wczytaj <ścieżka_do_taśmy> <ścieżka_do_pliku>
|
adds the records described in test file to the tape
|
||||||
wczytuje rekordy z podanego pliku testowego na taśmę
|
sort <path_to_tape> [options]
|
||||||
sortuj <ścieżka_do_taśmy> [opcje]
|
sorts the provided tape displaying its contents before and after sorting
|
||||||
sortuje podaną taśmę wypisując jej zawartość na
|
when option 'v' is provided then tape will be displayed after each
|
||||||
początku i na końcu operacji.
|
phase
|
||||||
Gdy zostanie podana opcja 'v', wówczas taśma będzie
|
display <path_to_tape>
|
||||||
wyświetlana po każdej z faz
|
displays the tape's records and information how many series and records it
|
||||||
wyświetl <ścieżka_do_taśmy>
|
contains. Also when displaying records it is shown when each of series
|
||||||
wyświetla zawartość taśmy i jej metadane m.in.:
|
ends
|
||||||
liczbę biegów (serii)
|
exit
|
||||||
liczbę rekordów
|
gracefully exits
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print("\nProjekt SBD - sortowanie metodą scalania naturalnego (2+1)")
|
print("\nSorting using natural merge method (2+1)")
|
||||||
print("Autor: Maciej Krzyżanowski [188872]\n")
|
print("Author: Maciej Krzyżanowski\n")
|
||||||
should_run = True
|
should_run = True
|
||||||
while should_run:
|
while should_run:
|
||||||
cmd_line = input("> ")
|
cmd_line = input("> ")
|
||||||
match cmd_line.split():
|
match cmd_line.split():
|
||||||
case ["wyczyść", tape_path]:
|
case ["clear", tape_path]:
|
||||||
print(f"[ .. ] Czyszczenie taśmy {tape_path}")
|
print(f"[ .. ] Clearing a tape {tape_path}")
|
||||||
if os.path.isfile(tape_path):
|
if os.path.isfile(tape_path):
|
||||||
os.remove(tape_path)
|
os.remove(tape_path)
|
||||||
print(f"[ :) ] Wyczyszczono taśmę")
|
print(f"[ :) ] Cleared the tape")
|
||||||
else:
|
else:
|
||||||
print(f"[ :( ] Taśma o podanej ścieżce nie istnieje")
|
print(f"[ :( ] There does not exist a tape at provided path")
|
||||||
case ["genlos", tape_path, number_of_records, *options]:
|
case ["genrandom", tape_path, number_of_records, *options]:
|
||||||
if "o" in options:
|
if "o" in options:
|
||||||
write_buffer = WriteBuffer(tape_path)
|
write_buffer = WriteBuffer(tape_path)
|
||||||
else:
|
else:
|
||||||
@ -421,14 +421,14 @@ while should_run:
|
|||||||
new_record = Record(new_set)
|
new_record = Record(new_set)
|
||||||
write_buffer.write_next(new_record)
|
write_buffer.write_next(new_record)
|
||||||
write_buffer.flush()
|
write_buffer.flush()
|
||||||
print(f"[ :) ] Dopisano {number_of_records} nowych rekordów do " +
|
print(f"[ :) ] Added {number_of_records} new records to " +
|
||||||
f"taśmy {tape_path}")
|
f"tape {tape_path}")
|
||||||
case ["wyświetl", tape_path]:
|
case ["display", tape_path]:
|
||||||
print(f"[ :) ] Wyświetlam taśmę {tape_path}")
|
print(f"[ :) ] Displaying tape {tape_path}")
|
||||||
print_tape(tape_path)
|
print_tape(tape_path)
|
||||||
case ["dopisz", tape_path, *set_elements]:
|
case ["add", tape_path, *set_elements]:
|
||||||
if len(set_elements) == 0:
|
if len(set_elements) == 0:
|
||||||
print("[ :( ] Nie podano ani jednego rekordu")
|
print("[ :( ] No number was given")
|
||||||
continue
|
continue
|
||||||
set_elements = [int(x) for x in set_elements]
|
set_elements = [int(x) for x in set_elements]
|
||||||
new_record = Record(set_elements)
|
new_record = Record(set_elements)
|
||||||
@ -436,22 +436,22 @@ while should_run:
|
|||||||
write_buffer.write_next(new_record)
|
write_buffer.write_next(new_record)
|
||||||
write_buffer.flush()
|
write_buffer.flush()
|
||||||
print(f"[ :) ] Dopisano podany rekord na taśmę")
|
print(f"[ :) ] Dopisano podany rekord na taśmę")
|
||||||
case ["sortuj", tape_path, *options]:
|
case ["sort", tape_path, *options]:
|
||||||
print(f"[ .. ] Sortowanie taśmy {tape_path}")
|
print(f"[ .. ] Sorting tape {tape_path}")
|
||||||
print(f"[ -v ] Wyświetlam taśmę przed posortowaniem:")
|
print(f"[ -v ] Displaying tape before sorting:")
|
||||||
print_tape(tape_path)
|
print_tape(tape_path)
|
||||||
if "v" in options:
|
if "v" in options:
|
||||||
sort_info = tape_sort(tape_path, print_after_phase=True)
|
sort_info = tape_sort(tape_path, print_after_phase=True)
|
||||||
else:
|
else:
|
||||||
sort_info = tape_sort(tape_path)
|
sort_info = tape_sort(tape_path)
|
||||||
print(f"[ -v ] Wyświetlam taśmę po posortowaniu:")
|
print(f"[ -v ] Displaying tape after sorting:")
|
||||||
print_tape(tape_path)
|
print_tape(tape_path)
|
||||||
print(f"[ :) ] Taśma {tape_path} posortowana!")
|
print(f"[ :) ] Tape {tape_path} sorted!")
|
||||||
print(f"[ -v ] Metadane sortowania")
|
print(f"[ -v ] Sorting metadata:")
|
||||||
print(f"[ .. ] Liczba faz {sort_info.phases_count}")
|
print(f"[ .. ] Phase count: {sort_info.phases_count}")
|
||||||
print(f"[ .. ] Liczba odczytów {sort_info.reads_count}")
|
print(f"[ .. ] Reads count: {sort_info.reads_count}")
|
||||||
print(f"[ .. ] Liczba zapisów {sort_info.writes_count}")
|
print(f"[ .. ] Writes count: {sort_info.writes_count}")
|
||||||
case ["wczytaj", tape_path, test_file_path]:
|
case ["load", tape_path, test_file_path]:
|
||||||
wb = WriteBuffer(tape_path, append_mode=True)
|
wb = WriteBuffer(tape_path, append_mode=True)
|
||||||
count = 0
|
count = 0
|
||||||
with open(test_file_path) as test_file:
|
with open(test_file_path) as test_file:
|
||||||
@ -461,12 +461,12 @@ while should_run:
|
|||||||
wb.write_next(new_record)
|
wb.write_next(new_record)
|
||||||
count += 1
|
count += 1
|
||||||
wb.flush()
|
wb.flush()
|
||||||
print(f"[ :) ] Dopisano {count} rekordów na taśmę")
|
print(f"[ :) ] Added {count} records to tape")
|
||||||
case ["pomoc"]:
|
case ["help"]:
|
||||||
print(help_page)
|
print(help_page)
|
||||||
case ["wyjście"]:
|
case ["exit"]:
|
||||||
print("[ :) ] Do widzenia!")
|
print("[ :) ] Goodbye!")
|
||||||
should_run = False
|
should_run = False
|
||||||
case _:
|
case _:
|
||||||
print("[ :( ] Nie znam takiej komendy")
|
print("[ :( ] I don't know such a command")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user