OrderedDict Class Reference


Public Member Functions

def __delitem__
def __eq__
def __init__
def __iter__
def __ne__
def __reduce__
def __repr__
def __reversed__
def __setitem__
def clear
def copy
def fromkeys
def items
def iteritems
def iterkeys
def itervalues
def keys
def pop
def popitem
def setdefault
def update
def values
def viewitems
def viewkeys
def viewvalues

Detailed Description

Definition at line 18 of file odict.py.


Member Function Documentation

def __delitem__ (   self,
  key,
  dict_delitem = dict.__delitem__ 
)

Definition at line 56 of file odict.py.

00056                                                              :
00057         'od.__delitem__(y) <==> del od[y]'
00058         # Deleting an existing item uses self.__map to find the link which is
00059         # then removed by updating the links in the predecessor and successor nodes.
00060         dict_delitem(self, key)
00061         link_prev, link_next, key = self.__map.pop(key)
00062         link_prev[1] = link_next
00063         link_next[0] = link_prev
00064 
    def __iter__(self):

def __eq__ (   self,
  other 
)

od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
while comparison to a regular mapping is order-insensitive.

Definition at line 237 of file odict.py.

00237                            :
00238         '''od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
00239         while comparison to a regular mapping is order-insensitive.
00240 
00241         '''
00242         if isinstance(other, OrderedDict):
00243             return len(self)==len(other) and self.items() == other.items()
00244         return dict.__eq__(self, other)
00245 
    def __ne__(self, other):

def __init__ (   self,
  args,
  kwds 
)

Initialize an ordered dictionary.  Signature is the same as for
regular dictionaries, but keyword arguments are not recommended
because their insertion order is arbitrary.

Definition at line 30 of file odict.py.

00030                                      :
00031         '''Initialize an ordered dictionary.  Signature is the same as for
00032         regular dictionaries, but keyword arguments are not recommended
00033         because their insertion order is arbitrary.
00034 
00035         '''
00036         if len(args) > 1:
00037             raise TypeError('expected at most 1 arguments, got %d' % len(args))
00038         try:
00039             self.__root
00040         except AttributeError:
00041             self.__root = root = []                     # sentinel node
00042             root[:] = [root, root, None]
00043             self.__map = {}
00044         self.__update(*args, **kwds)
00045 
    def __setitem__(self, key, value, dict_setitem=dict.__setitem__):

def __iter__ (   self  ) 

Definition at line 65 of file odict.py.

00065                       :
00066         'od.__iter__() <==> iter(od)'
00067         root = self.__root
00068         curr = root[1]
00069         while curr is not root:
00070             yield curr[2]
00071             curr = curr[1]
00072 
    def __reversed__(self):

def __ne__ (   self,
  other 
)

Definition at line 246 of file odict.py.

00246                            :
00247         return not self == other
00248 
00249     # -- the following methods are only used in Python 2.7 --
00250 
    def viewkeys(self):

def __reduce__ (   self  ) 

Definition at line 212 of file odict.py.

00212                         :
00213         'Return state information for pickling'
00214         items = [[k, self[k]] for k in self]
00215         inst_dict = vars(self).copy()
00216         for k in vars(OrderedDict()):
00217             inst_dict.pop(k, None)
00218         if inst_dict:
00219             return (self.__class__, (items,), inst_dict)
00220         return self.__class__, (items,)
00221 
    def copy(self):

def __repr__ (   self,
  _repr_running = {} 
)

Definition at line 199 of file odict.py.

00199                                      {}):
00200         'od.__repr__() <==> repr(od)'
00201         call_key = id(self), _get_ident()
00202         if call_key in _repr_running:
00203             return '...'
00204         _repr_running[call_key] = 1
00205         try:
00206             if not self:
00207                 return '%s()' % (self.__class__.__name__,)
00208             return '%s(%r)' % (self.__class__.__name__, self.items())
00209         finally:
00210             del _repr_running[call_key]
00211 

def __reversed__ (   self  ) 

Definition at line 73 of file odict.py.

00073                           :
00074         'od.__reversed__() <==> reversed(od)'
00075         root = self.__root
00076         curr = root[0]
00077         while curr is not root:
00078             yield curr[2]
00079             curr = curr[0]
00080 
    def clear(self):

def __setitem__ (   self,
  key,
  value,
  dict_setitem = dict.__setitem__ 
)

Definition at line 46 of file odict.py.

00046                                                                     :
00047         'od.__setitem__(i, y) <==> od[i]=y'
00048         # Setting a new item creates a new link which goes at the end of the linked
00049         # list, and the inherited dictionary is updated with the new key/value pair.
00050         if key not in self:
00051             root = self.__root
00052             last = root[0]
00053             last[1] = root[0] = self.__map[key] = [last, root, key]
00054         dict_setitem(self, key, value)
00055 
    def __delitem__(self, key, dict_delitem=dict.__delitem__):

def clear (   self  ) 

Definition at line 81 of file odict.py.

00081                    :
00082         'od.clear() -> None.  Remove all items from od.'
00083         try:
00084             for node in self.__map.itervalues():
00085                 del node[:]
00086             root = self.__root
00087             root[:] = [root, root, None]
00088             self.__map.clear()
00089         except AttributeError:
00090             pass
00091         dict.clear(self)
00092 
    def popitem(self, last=True):

def copy (   self  ) 

Definition at line 222 of file odict.py.

00222                   :
00223         'od.copy() -> a shallow copy of od'
00224         return self.__class__(self)
00225 
00226     @classmethod
    def fromkeys(cls, iterable, value=None):

def fromkeys (   cls,
  iterable,
  value = None 
)

OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
and values equal to v (which defaults to None).

Definition at line 227 of file odict.py.

00227                                            :
00228         '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
00229         and values equal to v (which defaults to None).
00230 
00231         '''
00232         d = cls()
00233         for key in iterable:
00234             d[key] = value
00235         return d
00236 
    def __eq__(self, other):

def items (   self  ) 

Definition at line 126 of file odict.py.

00126                    :
00127         'od.items() -> list of (key, value) pairs in od'
00128         return [(key, self[key]) for key in self]
00129 
    def iterkeys(self):

def iteritems (   self  ) 

Definition at line 139 of file odict.py.

00139                        :
00140         'od.iteritems -> an iterator over the (key, value) items in od'
00141         for k in self:
00142             yield (k, self[k])
00143 
    def update(*args, **kwds):

def iterkeys (   self  ) 

Definition at line 130 of file odict.py.

00130                       :
00131         'od.iterkeys() -> an iterator over the keys in od'
00132         return iter(self)
00133 
    def itervalues(self):

def itervalues (   self  ) 

Definition at line 134 of file odict.py.

00134                         :
00135         'od.itervalues -> an iterator over the values in od'
00136         for k in self:
00137             yield self[k]
00138 
    def iteritems(self):

def keys (   self  ) 

Definition at line 118 of file odict.py.

00118                   :
00119         'od.keys() -> list of keys in od'
00120         return list(self)
00121 
    def values(self):

def pop (   self,
  key,
  default = __marker 
)

od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.

Definition at line 179 of file odict.py.

00179                                         :
00180         '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
00181         If key is not found, d is returned if given, otherwise KeyError is raised.
00182 
00183         '''
00184         if key in self:
00185             result = self[key]
00186             del self[key]
00187             return result
00188         if default is self.__marker:
00189             raise KeyError(key)
00190         return default
00191 
    def setdefault(self, key, default=None):

def popitem (   self,
  last = True 
)

od.popitem() -> (k, v), return and remove a (key, value) pair.
Pairs are returned in LIFO order if last is true or FIFO order if false.

Definition at line 93 of file odict.py.

00093                                 :
00094         '''od.popitem() -> (k, v), return and remove a (key, value) pair.
00095         Pairs are returned in LIFO order if last is true or FIFO order if false.
00096 
00097         '''
00098         if not self:
00099             raise KeyError('dictionary is empty')
00100         root = self.__root
00101         if last:
00102             link = root[0]
00103             link_prev = link[0]
00104             link_prev[1] = root
00105             root[0] = link_prev
00106         else:
00107             link = root[1]
00108             link_next = link[1]
00109             root[1] = link_next
00110             link_next[0] = root
00111         key = link[2]
00112         del self.__map[key]
00113         value = dict.pop(self, key)
00114         return key, value
00115 
00116     # -- the following methods do not depend on the internal structure --
00117 
    def keys(self):

def setdefault (   self,
  key,
  default = None 
)

Definition at line 192 of file odict.py.

00192                                            :
00193         'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
00194         if key in self:
00195             return self[key]
00196         self[key] = default
00197         return default
00198 
    def __repr__(self, _repr_running={}):

def update (   args,
  kwds 
)

od.update(E, **F) -> None.  Update od from dict/iterable E and F.

If E is a dict instance, does:           for k in E: od[k] = E[k]
If E has a .keys() method, does:         for k in E.keys(): od[k] = E[k]
Or if E is an iterable of items, does:   for k, v in E: od[k] = v
In either case, this is followed by:     for k, v in F.items(): od[k] = v

Definition at line 144 of file odict.py.

00144                              :
00145         '''od.update(E, **F) -> None.  Update od from dict/iterable E and F.
00146 
00147         If E is a dict instance, does:           for k in E: od[k] = E[k]
00148         If E has a .keys() method, does:         for k in E.keys(): od[k] = E[k]
00149         Or if E is an iterable of items, does:   for k, v in E: od[k] = v
00150         In either case, this is followed by:     for k, v in F.items(): od[k] = v
00151 
00152         '''
00153         if len(args) > 2:
00154             raise TypeError('update() takes at most 2 positional '
00155                             'arguments (%d given)' % (len(args),))
00156         elif not args:
00157             raise TypeError('update() takes at least 1 argument (0 given)')
00158         self = args[0]
00159         # Make progressively weaker assumptions about "other"
00160         other = ()
00161         if len(args) == 2:
00162             other = args[1]
00163         if isinstance(other, dict):
00164             for key in other:
00165                 self[key] = other[key]
00166         elif hasattr(other, 'keys'):
00167             for key in other.keys():
00168                 self[key] = other[key]
00169         else:
00170             for key, value in other:
00171                 self[key] = value
00172         for key, value in kwds.items():
00173             self[key] = value
00174 
    __update = update  # let subclasses override update without breaking __init__

def values (   self  ) 

Definition at line 122 of file odict.py.

00122                     :
00123         'od.values() -> list of values in od'
00124         return [self[key] for key in self]
00125 
    def items(self):

def viewitems (   self  ) 

Definition at line 259 of file odict.py.

00259                        :
00260         "od.viewitems() -> a set-like object providing a view on od's items"
00261         return ItemsView(self)
        return ItemsView(self)

def viewkeys (   self  ) 

Definition at line 251 of file odict.py.

00251                       :
00252         "od.viewkeys() -> a set-like object providing a view on od's keys"
00253         return KeysView(self)
00254 
    def viewvalues(self):

def viewvalues (   self  ) 

Definition at line 255 of file odict.py.

00255                         :
00256         "od.viewvalues() -> an object providing a view on od's values"
00257         return ValuesView(self)
00258 
    def viewitems(self):


The documentation for this class was generated from the following file:

Generated on Thu Apr 16 06:41:38 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6