MCPcopy
hub / github.com/redis/redis-py / add

Method add

redis/data_structure.py:18–30  ·  view source on GitHub ↗

Add item with weight, maintaining sorted order

(self, item: Any, weight: float)

Source from the content-addressed store, hash-verified

16 self._lock = threading.RLock()
17
18 def add(self, item: Any, weight: float) -> None:
19 """Add item with weight, maintaining sorted order"""
20 with self._lock:
21 # Find insertion point using binary search
22 left, right = 0, len(self._items)
23 while left < right:
24 mid = (left + right) // 2
25 if self._items[mid][1] < weight:
26 right = mid
27 else:
28 left = mid + 1
29
30 self._items.insert(left, (item, weight))
31
32 def remove(self, item):
33 """Remove first occurrence of item"""

Callers 15

test_add_itemsMethod · 0.95
test_remove_itemsMethod · 0.95
test_update_weightsMethod · 0.95
create_weighted_listFunction · 0.95
create_weighted_listFunction · 0.95
update_weightMethod · 0.95
databasesMethod · 0.95
databasesMethod · 0.95
dt_topk.pyFile · 0.45

Calls 1

insertMethod · 0.45