1. TortoiseHg
  2. TortoiseHg
  3. thg

Commits

TK Soh  committed 1c90692

hggtk/shlib: add compact() method to SimpleMRUList class

  • Participants
  • Parent commits 8669972
  • Branches default

Comments (0)

Files changed (1)

File hggtk/shlib.py

View file
 import time
 
 class SimpleMRUList(object):
-    def __init__(self, size=10, reflist=[]):
+    def __init__(self, size=10, reflist=[], compact=True):
         self._size = size
         self._list = reflist
+        if compact:
+            self.compact()
 
     def __iter__(self):
         for elem in self._list:
         while len(self._list) > self._size:
             del self._list[-1]
 
+    def compact(self):
+        ''' remove duplicate in list '''
+        list = []
+        for v in self._list:
+            if v not in list:
+                list.append(v)
+        self._list[:] = list
+
+
 class Settings(object):
     version = 1.0