Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Tolmachev committed Nov 23, 2022
1 parent b1a2e8e commit 193e49f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dictdatabase/io_unsafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def partial_read_only(db_name: str, key: str) -> dict | None:

# Not found in index file, search for key in the entire file
all_file_bytes = io_bytes.read(db_name)
start, end, found = searching.search_value_by_key(all_file_bytes, key)
start, end, found = searching.search_value_position_in_db(all_file_bytes, key)
if not found:
return None
value_bytes = all_file_bytes[start:end]
Expand Down Expand Up @@ -185,7 +185,7 @@ def get_partial_file_handle(db_name: str, key: str) -> PartialFileHandle:
return partial_handle

# Not found in index file, search for key in the entire file
key_start, key_end, found = searching.search_key(all_file_bytes, key)
key_start, key_end, found = searching.search_key_position_in_db(all_file_bytes, key)

if not found:
raise KeyError(f"Key \"{key}\" not found in db \"{db_name}\"")
Expand Down
10 changes: 5 additions & 5 deletions dictdatabase/searching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dictdatabase import utils


def find_start_end_in_bytes(file: bytes, key: str) -> Tuple[int, int, bool]:
def find_key_position_in_bytes(file: bytes, key: str) -> Tuple[int, int, bool]:
"""
It finds the start and end indices of the value of a key in a JSON file
Expand All @@ -25,7 +25,7 @@ def find_start_end_in_bytes(file: bytes, key: str) -> Tuple[int, int, bool]:
return start, end, True


def search_key(file: bytes, key: str, glom_searching=True) -> Tuple[int, int, bool]:
def search_key_position_in_db(file: bytes, key: str, glom_searching=True) -> Tuple[int, int, bool]:
original_value_start = 0
original_value_end = len(file)
original_key_start = 0
Expand All @@ -36,14 +36,14 @@ def search_key(file: bytes, key: str, glom_searching=True) -> Tuple[int, int, bo
return -1, -1, False
original_key_end = original_value_start + key_end
original_key_start = original_value_start + key_start
value_start, value_end, found = find_start_end_in_bytes(file, k)
value_start, value_end, found = find_key_position_in_bytes(file, k)
original_value_end = original_value_start + original_value_end
original_value_start += value_start
file = file[original_value_start:original_value_end]
return original_key_start, original_key_end, True


def search_value_by_key(
def search_value_position_in_db(
all_file_bytes: bytes, key: str, glom_searching=True
) -> Tuple[int, int, bool]:
"""
Expand All @@ -61,7 +61,7 @@ def search_value_by_key(
original_start = 0
original_end = len(all_file_bytes)
for k in key.split(".") if glom_searching else [key]:
start, end, found = find_start_end_in_bytes(
start, end, found = find_key_position_in_bytes(
all_file_bytes[original_start:original_end], k
)
if not found:
Expand Down

0 comments on commit 193e49f

Please sign in to comment.