Selfie
Loading...
Searching...
No Matches
selfie_lib.ArrayMap Namespace Reference

Classes

class  _ArrayMapEntries
 
class  _ArrayMapKeys
 
class  ArrayMap
 
class  ArraySet
 
class  ListBackedSet
 

Functions

int _compare_normal (a, b)
 
int _compare_string_slash_first (str a, str b)
 
int _binary_search (data, item)
 

Variables

 T = TypeVar("T")
 
 V = TypeVar("V")
 
 K = TypeVar("K")
 

Function Documentation

◆ _binary_search()

int selfie_lib.ArrayMap._binary_search (   data,
  item 
)
protected

Definition at line 23 of file ArrayMap.py.

23def _binary_search(data, item) -> int:
24 compare_func = (
25 _compare_string_slash_first if isinstance(item, str) else _compare_normal
26 )
27 low, high = 0, len(data) - 1
28 while low <= high:
29 mid = (low + high) // 2
30 mid_val = data[mid]
31 comparison = compare_func(mid_val, item)
32
33 if comparison < 0:
34 low = mid + 1
35 elif comparison > 0:
36 high = mid - 1
37 else:
38 return mid # item found
39 return -(low + 1) # item not found
40
41

◆ _compare_normal()

int selfie_lib.ArrayMap._compare_normal (   a,
  b 
)
protected

Definition at line 10 of file ArrayMap.py.

10def _compare_normal(a, b) -> int:
11 if a == b:
12 return 0
13 elif a < b:
14 return -1
15 else:
16 return 1
17
18

◆ _compare_string_slash_first()

int selfie_lib.ArrayMap._compare_string_slash_first ( str  a,
str  b 
)
protected

Definition at line 19 of file ArrayMap.py.

19def _compare_string_slash_first(a: str, b: str) -> int:
20 return _compare_normal(a.replace("/", "\0"), b.replace("/", "\0"))
21
22

Variable Documentation

◆ K

selfie_lib.ArrayMap.K = TypeVar("K")

Definition at line 7 of file ArrayMap.py.

◆ T

selfie_lib.ArrayMap.T = TypeVar("T")

Definition at line 5 of file ArrayMap.py.

◆ V

selfie_lib.ArrayMap.V = TypeVar("V")

Definition at line 6 of file ArrayMap.py.