Skip to content
Snippets Groups Projects
Commit 52f7a746 authored by hdd29's avatar hdd29
Browse files

Add the python part for l7

parent 9c5484e7
No related branches found
No related tags found
No related merge requests found
...@@ -4,10 +4,30 @@ The difference is that the two functions take different argument type to travers ...@@ -4,10 +4,30 @@ The difference is that the two functions take different argument type to travers
Meanwhile, "addSuffix" has the prefix as the input. It looks up in the statetab if there is that prefix in there, Meanwhile, "addSuffix" has the prefix as the input. It looks up in the statetab if there is that prefix in there,
then add the suffix to the state that has that prefix. if not, it creates 1. Then it add the suffix in to the then add the suffix to the state that has that prefix. if not, it creates 1. Then it add the suffix in to the
suffix component of the newly created state with the new prefix. suffix component of the newly created state with the new prefix.
Q2: Q2:
Lookup does what its name says, to look up if there exists a prefix (that is the same as the input prefix) in the states in the statetab. If the prefix is found in a particular state, the pointer to the state is returned. If not, the function will look into the boolean argument "create" given to it and decide whether to create a new state with the input prefix or not. Function add() and generate() call this function.
Q3: Q3:
include a picture of the table later include a picture of the table later
The following table is created with random hash value assigned to the states and assuming the prefix pairs (NULL; it's) and (a; new) have the same hash values; (NULL;NULL) and (it's; a) have the same hash value.
statetab[hashValue 1] --> | next | -----------> | next | ---> NULL
| pref[0] | ---> NULL | pref[0] | ---> It's
| pref[1] | ---> NULL | pref[1] | ---> a
| suffix | ---> It's | suffix | ---> new
statetab[hashValue 2] --> | next | -----------> | next | ---> NULL
| pref[0] | ---> NULL | pref[0] | ---> a
| pref[1] | ---> It's | pref[1] | ---> new
| suffix | ---> a | suffix | ---> dawn
statetab[hashValue 3] --> | next | ---> NULL
| pref[0] | ---> new
| pref[1] | ---> dawn
| suffix | ---> NULL
Number of pointers: Number of pointers:
It's : 3 It's : 3
a: 3 a: 3
...@@ -67,4 +87,17 @@ Q13: Disadvantage: ...@@ -67,4 +87,17 @@ Q13: Disadvantage:
In contrast to the advantage of the C implementation, this one consume more memory as it stores multiple duplications of the same word in different suffix vectors and also as prefixes in many places. In contrast to the advantage of the C implementation, this one consume more memory as it stores multiple duplications of the same word in different suffix vectors and also as prefixes in many places.
Q14: Q14:
The prefix are store in tuples of 2 elements that are keys to a python dictionary
Q15:
the Python built in dictionary replaces the hash table
Q16: The list of suffices is store in a list, which is the value to the table dictionary
Q17:
Advantages:
Take less lines of code to write the program that does the same objectives. The dictionary built in Python used a close hash function so there should not be collisions that happen as in the C implemetation.
Q18:
Disadvantages:
Takes more time to compile. Has to be interpreted first , then compiled. So the performance in terms of time elpapsed is worse than C and C++, which are directly compiled.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment