Сообщение Re[2]: А вы без подготовки сможете свой словарь написать? от 24.01.2020 10:41
Изменено 24.01.2020 10:44 Ватакуси
Re[2]: А вы без подготовки сможете свой словарь написать?
LVV>На С++ — без вопросов.
И разрешение коллизий? По памяти?
В упомянутом питоне это делается как-то так. Не самый простой алгоритм.
И разрешение коллизий? По памяти?
В упомянутом питоне это делается как-то так. Не самый простой алгоритм.
DUMMY = 'dummy'
def openAddressingProbe(table, key, hash):
free_slot = None
perturb = hash
i = slot_index = hash & ma_mask
while table[slot_index] is not None and table[slot_index].key != key:
if table[slot_index].key is DUMMY and free_slot is None:
free_slot = slot_index
i = (5 * i + perturb + 1)
slot_index = i & ma_mask
perturb >>= 5
if table[slot_index] is None and free_slot is not None:
return free_slot
return slot_index
Re[2]: А вы без подготовки сможете свой словарь написать?
LVV>На С++ — без вопросов.
И разрешение коллизий? По памяти?
В упомянутом питоне это делается как-то так. Не самый простой алгоритм.
И разрешение коллизий? По памяти?
В упомянутом питоне это делается как-то так. Не самый простой алгоритм.
"""ma_mask
Bitmask of the hash table, the table contains ma_mask + 1 slots. We store the
mask instead of the size because when we are looking up the entry for a key,
`slot = key_hash & mask` is used to get the slot index"""
DUMMY = 'dummy'
def openAddressingProbe(table, key, hash):
free_slot = None
perturb = hash
i = slot_index = hash & ma_mask
while table[slot_index] is not None and table[slot_index].key != key:
if table[slot_index].key is DUMMY and free_slot is None:
free_slot = slot_index
i = (5 * i + perturb + 1)
slot_index = i & ma_mask
perturb >>= 5
if table[slot_index] is None and free_slot is not None:
return free_slot
return slot_index