How to Use - LBeghini/Hash-Functions GitHub Wiki
The first thing asked by the program is the size of the hash table, and has some stricted rules:
- Integer
- Greater than 1
Table size: 12
โโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโโคโโโโโโโ
โ 0 โ 1 โ 2 โ 3 โ 4 โ 5 โ 6 โ 7 โ 8 โ 9 โ 10 โ 11 โ
โโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโโชโโโโโโโก
โ โ โ โ โ โ โ โ โ โ โ โ โ
โโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโโงโโโโโโโ
According to the table size, the rule of the hash function changes.
If the table size is a prime number, then the rule is set to be the mod of the table size:
h(x) = x mod TABLE.size
If the table size is not a prime number, then rule is set to be the mod of the previous table size prime number:
h(x) = x mod previous_prime(TABLE.size)
The insertion function receives an integer, and according to the defined hash function, it will try to put that number in its correct index. If a key is taking its place, it will try to place it in the nearest neighbors, until it finds an empty place or until the entire table has already been searched, meaning that it is full.
-i, --insert
Any integer positive number
<COMMAND> [key]
Returns 0
if hash table is full
Returns -1
if the key already exists in table
OPERATION: -i 12
or
OPERATION: --insert 12
โโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโโคโโโโโโโ
โ 0 โ 1 โ 2 โ 3 โ 4 โ 5 โ 6 โ 7 โ 8 โ 9 โ 10 โ 11 โ
โโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโโชโโโโโโโก
โ 12 โ โ โ โ โ โ โ โ โ โ โ โ
โโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโโงโโโโโโโ
The search function receives a key and will try to find the key in its correct index. If that index already has an key that is not that key that's been searched, it will try to find it in the nearest neighbors, until the entire table has been searched, meaning that the key is not there.
-s, --search
Any integer positive number
<COMMAND> [key]
Returns the index of the searched key
Returns the error Not found
if key not found
OPERATION: -s 12
or
OPERATION: --search 12
RESULT: 0
The delete function receives a key integer and will use the search function to get the index. If the index is found, it will remove the key and reset the table. Reset means that it will remove all keys in the table and insert it again, to fix the positions.
-d, --delete
Any integer positive number
<COMMAND> [key]
Returns 0
if key not found
OPERATION: -d 12
or
OPERATION: --delete 12
โโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโคโโโโโโโคโโโโโโโ
โ 0 โ 1 โ 2 โ 3 โ 4 โ 5 โ 6 โ 7 โ 8 โ 9 โ 10 โ 11 โ
โโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโโชโโโโโโโก
โ โ โ โ โ โ โ โ โ โ โ โ โ
โโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโงโโโโโโโงโโโโโโโ
The hash function returns the structure of the function that is being used to map to the table.
-h, --hash
<COMMAND>
Returns the structure of the function being used to map in the hash table
OPERATION: -h
or
OPERATION: --hash
h(x) = x mod 11