Move an existing element to the end (or beginning if last is false). Raise KeyError if the element does not exist.
(self, key, last=True)
| 192 | return key, value |
| 193 | |
| 194 | def move_to_end(self, key, last=True): |
| 195 | '''Move an existing element to the end (or beginning if last is false). |
| 196 | |
| 197 | Raise KeyError if the element does not exist. |
| 198 | ''' |
| 199 | link = self.__map[key] |
| 200 | link_prev = link.prev |
| 201 | link_next = link.next |
| 202 | soft_link = link_next.prev |
| 203 | link_prev.next = link_next |
| 204 | link_next.prev = link_prev |
| 205 | root = self.__root |
| 206 | if last: |
| 207 | last = root.prev |
| 208 | link.prev = last |
| 209 | link.next = root |
| 210 | root.prev = soft_link |
| 211 | last.next = link |
| 212 | else: |
| 213 | first = root.next |
| 214 | link.prev = root |
| 215 | link.next = first |
| 216 | first.prev = soft_link |
| 217 | root.next = link |
| 218 | |
| 219 | def __sizeof__(self): |
| 220 | sizeof = _sys.getsizeof |
no outgoing calls