MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / add

Method add

other/lfu_cache.py:114–129  ·  view source on GitHub ↗

Adds the given node at the tail of the list and shifting it to proper position

(self, node: DoubleLinkedListNode[T, U])

Source from the content-addressed store, hash-verified

112 return ",\n ".join(rep)
113
114 def add(self, node: DoubleLinkedListNode[T, U]) -> None:
115 """
116 Adds the given node at the tail of the list and shifting it to proper position
117 """
118
119 previous = self.rear.prev
120
121 # All nodes other than self.head are guaranteed to have non-None previous
122 assert previous is not None
123
124 previous.next = node
125 node.prev = previous
126 self.rear.prev = node
127 node.next = self.rear
128 node.freq += 1
129 self._position_node(node)
130
131 def _position_node(self, node: DoubleLinkedListNode[T, U]) -> None:
132 """

Callers 2

getMethod · 0.45
putMethod · 0.45

Calls 1

_position_nodeMethod · 0.95

Tested by

no test coverage detected