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
{ | |
"definitions": { | |
"<script>alert(1)</script>": { | |
"type": "object" | |
}, | |
"Feedback": { | |
"properties": { | |
"feedback": { | |
"type": "integer" | |
} |
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
{ | |
"definitions": { | |
"Device": { | |
"type": "object" | |
}, | |
"Feedback": { | |
"properties": { | |
"feedback": { | |
"type": "integer" | |
} |
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
def __getitem__(self, key: str) -> Entry: | |
"""subscript method - object[key] | |
use hashing function to find the index""" | |
entry = Entry(key) | |
index = entry.hash % self.actual_size | |
found = self.entries[index] | |
if found == None: | |
raise KeyError | |
return found |
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
def __setitem__(self, key: str, value: Any) -> int: | |
"""allow insertion of items with object[key] = value""" | |
entry = Entry(key, value) | |
index = entry.hash % self.actual_size | |
self.entries[index] = entry | |
return index |
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
def __init__(self, size=10): | |
self.entries = [None for _ in range(size * 2)] | |
self.size = size | |
self.actual_size = size * 2 | |
self.filled_entries = 0 | |
def __setitem__(self, key: str, value: Any) -> int: | |
"""allow insertion of items with object[key] = value""" | |
if self.filled_entries == self.size: | |
# no more room |
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
table = HashTable() | |
names = [ | |
"Eden Marriott", | |
"Sebastian Frame", | |
"Cassia Hicks", | |
"Bert Blankenship", | |
"Clarence Hughes", | |
"Clay Burch", | |
"Linda Holmes", | |
"Felix Galloway", |
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
found = 0 | |
for num in int_array: | |
if num in d: | |
found += 1 |
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
int_array = array.array("i", range(10 ** 5)) | |
d = dict.fromkeys(int_array, None) | |
l = list(range(10 ** 5)) |
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
class Entry(object): | |
def __init__(self, key: str, value=None): | |
self.key = key | |
self.value = value | |
@property | |
def hash(self) -> int: | |
"""return entry's hash""" | |
return len(self.key) |
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
@property | |
def hash(self) -> int: | |
"""return entry's hash""" | |
return len(self.key) |
NewerOlder