1from abc
import ABC, abstractmethod
2from collections.abc
import ItemsView, Iterator, Mapping, Set
3from typing
import Any, TypeVar, Union
25 _compare_string_slash_first
if isinstance(item, str)
else _compare_normal
27 low, high = 0, len(data) - 1
29 mid = (low + high) // 2
31 comparison = compare_func(mid_val, item)
47 def __getitem__(self, index: Union[int, slice]) -> Union[T, list[T]]: ...
63 raise NotImplementedError(
"Use ArraySet.empty() or other class methods instead")
66 def __create(cls, data: list[K]) ->
"ArraySet[K]":
67 instance = super().__new__(cls)
68 instance.__data = data
75 def empty(cls) -> "ArraySet[K]":
76 if not hasattr(cls,
"__EMPTY"):
83 def __getitem__(self, index: Union[int, slice]) -> Union[K, list[K]]:
91 insert_at = -(index + 1)
93 new_data.insert(insert_at, element)
94 return ArraySet.__create(new_data)
102 return len(self.
__data) // 2
105 if isinstance(index, slice):
109 index.start * 2
if index.start
else 0,
110 index.stop * 2
if index.stop
else len(self.
__data),
111 index.step * 2
if index.step
else 2,
115 return self.
__data[2 * index]
118 return (self.
__data[i]
for i
in range(0, len(self.
__data), 2))
126 return len(self.
__data) // 2
129 if isinstance(index, slice):
133 index.start * 2
if index.start
else 0,
134 index.stop * 2
if index.stop
else len(self.
__data),
135 index.step * 2
if index.step
else 2,
139 return (self.
__data[2 * index], self.
__data[2 * index + 1])
148 __data: list[Union[K, V]]
149 __keys: ListBackedSet[K]
152 raise NotImplementedError(
"Use ArrayMap.empty() or other class methods instead")
155 def __create(cls, data: list[Union[K, V]]) ->
"ArrayMap[K, V]":
156 instance = cls.__new__(cls)
157 instance.__data = data
163 if not hasattr(cls,
"__EMPTY"):
167 def keys(self) -> ListBackedSet[K]:
170 def items(self) -> _ArrayMapEntries[K, V]:
188 def plus(self, key: K, value: V) ->
"ArrayMap[K, V]":
192 insert_at = -(index + 1)
194 new_data.insert(insert_at * 2, key)
195 new_data.insert(insert_at * 2 + 1, value)
196 return ArrayMap.__create(new_data)
200 adjusted_indices = [i * 2
for i
in indices] + [i * 2 + 1
for i
in indices]
201 adjusted_indices.sort(reverse=
True)
202 for index
in adjusted_indices:
204 return ArrayMap.__create(new_data)
212 insert_at = -(index + 1)
214 new_data.insert(insert_at * 2, key)
215 new_data.insert(insert_at * 2 + 1, value)
216 return ArrayMap.__create(new_data)
225 new_data[2 * index + 1] = value
228 insert_at = -(index + 1)
230 new_data.insert(insert_at * 2, key)
231 new_data.insert(insert_at * 2 + 1, value)
232 return ArrayMap.__create(new_data)
235 return "{" +
", ".join(f
"{k}: {v}" for k, v
in self.
items()) +
"}"
"ArrayMap[K, V]" plus(self, K key, V value)
"ArrayMap[K, V]" plus_or_noop_or_replace(self, K key, V value)
Iterator[K] __iter__(self)
"ArrayMap[K, V]" __create(cls, list[Union[K, V]] data)
"ArrayMap[K, V]" minus_sorted_indices(self, list[int] indices)
int _binary_search_key(self, K key)
V __getitem__(self, K key)
ListBackedSet[K] keys(self)
"ArrayMap[K, V]" empty(cls)
_ArrayMapEntries[K, V] items(self)
"ArrayMap[K, V]" plus_or_noop(self, K key, V value)
Union[K, list[K]] __getitem__(self, Union[int, slice] index)
"ArraySet[K]" __create(cls, list[K] data)
"ArraySet[K]" plusOrThis(self, K element)
Iterator[K] __iter__(self)
Iterator[T] __iter__(self)
int _binary_search(self, Any item)
Union[T, list[T]] __getitem__(self, Union[int, slice] index)
bool __contains__(self, Any item)
__init__(self, list[Union[K, V]] data)
Iterator[tuple[K, V]] __iter__(self)
__getitem__(self, Union[int, slice] index)
__getitem__(self, Union[int, slice] index)
__init__(self, list[Union[K, V]] data)
Iterator[K] __iter__(self)
int _binary_search(data, item)
int _compare_string_slash_first(str a, str b)
int _compare_normal(a, b)