Patchwork [2,of,2] sortdict: add insert method

login
register
mail settings
Submitter Sean Farley
Date Nov. 6, 2014, 11:09 p.m.
Message ID <59735d23b2c2014689f8.1415315395@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/6622/
State Accepted
Commit 79858e66a7cec5c2273a53fe42c65a248e979211
Delegated to: Augie Fackler
Headers show

Comments

Sean Farley - Nov. 6, 2014, 11:09 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1413401959 25200
#      Wed Oct 15 12:39:19 2014 -0700
# Node ID 59735d23b2c2014689f811f5e83c696bd70e1f8e
# Parent  45fd23c47bb429c84e28a3303fb2a1097c5082e2
sortdict: add insert method

Again, nothing really fancy here. Since we already have a sorted dictionary,
this patch adds the ability to insert a key into a specific location.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -369,10 +369,13 @@  class sortdict(dict):
         return self._list
     def iterkeys(self):
         return self._list.__iter__()
     def iteritems(self):
         return self.items().__iter__()
+    def insert(self, index, key, val):
+        self._list.insert(index, key)
+        dict.__setitem__(self, key, val)
 
 class lrucachedict(object):
     '''cache most recent gets from or sets to this dictionary'''
     def __init__(self, maxsize):
         self._cache = {}