diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-21 21:37:52 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-21 21:37:52 -0500 |
| commit | b79a5e7640fc1c8ca7acce5bfd2509ddf0102080 (patch) | |
| tree | 4fce95f955d2f1ca15ded2c3030e78b79e82cb68 /lib/sqlalchemy/util | |
| parent | dff4e0591eee3def7c4c38666c8fc581c327aa87 (diff) | |
| download | sqlalchemy-b79a5e7640fc1c8ca7acce5bfd2509ddf0102080.tar.gz | |
- another heap of inlinings and now I really have to be done with this
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/_collections.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 4ab52c3d6..2735f5e80 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -583,9 +583,16 @@ column_dict = dict ordered_column_set = OrderedSet populate_column_dict = PopulateDict -def unique_list(seq, compare_with=set): - seen = compare_with() - return [x for x in seq if x not in seen and not seen.add(x)] +def unique_list(seq, hashfunc=None): + seen = {} + if not hashfunc: + return [x for x in seq + if x not in seen + and not seen.__setitem__(x, True)] + else: + return [x for x in seq + if hashfunc(x) not in seen + and not seen.__setitem__(hashfunc(x), True)] class UniqueAppender(object): """Appends items to a collection ensuring uniqueness. @@ -596,19 +603,19 @@ class UniqueAppender(object): def __init__(self, data, via=None): self.data = data - self._unique = IdentitySet() + self._unique = {} if via: self._data_appender = getattr(data, via) elif hasattr(data, 'append'): self._data_appender = data.append elif hasattr(data, 'add'): - # TODO: we think its a set here. bypass unneeded uniquing logic ? self._data_appender = data.add def append(self, item): - if item not in self._unique: + id_ = id(item) + if id_ not in self._unique: self._data_appender(item) - self._unique.add(item) + self._unique[id_] = True def __iter__(self): return iter(self.data) |
