~ubuntu-branches/debian/sid/meliae/sid

« back to all changes in this revision

Viewing changes to meliae/_intset.pyx

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-20 18:26:22 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100720182622-b0ks0nu34mify1lj
Tags: upstream-0.2.1
ImportĀ upstreamĀ versionĀ 0.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
            perturb = perturb >> 5 # PERTURB_SHIFT
113
113
 
114
114
    def __contains__(self, val):
115
 
        cdef int_type c_val, *entry
116
 
        c_val = val
 
115
        cdef int_type i_val
 
116
        i_val = val
 
117
        return self._contains(i_val)
 
118
 
 
119
    cdef object _contains(self, int_type c_val):
 
120
        cdef int_type *entry
117
121
        if c_val == _singleton1:
118
122
            if self._has_singleton & 0x01:
119
123
                return True
200
204
            % (c_val, entry[0]))
201
205
 
202
206
    def add(self, val):
 
207
        """Add a new entry to the set."""
203
208
        self._add(val)
204
209
 
205
210
 
210
215
    addresses tend to be aligned on 16-byte boundaries (occasionally 8-byte,
211
216
    and even more rarely on 4-byte), as such the standard hash lookup has more
212
217
    collisions than desired.
 
218
 
 
219
    Also, addresses are considered to be unsigned longs by python, but
 
220
    Py_ssize_t is a signed long. Just treating it normally causes us to get a
 
221
    value overflow on 32-bits if the highest bit is set.
213
222
    """
214
223
 
 
224
    def add(self, val):
 
225
        cdef unsigned long ul_val
 
226
        ul_val = val
 
227
        self._add(<int_type>(ul_val))
 
228
 
 
229
    def __contains__(self, val):
 
230
        cdef unsigned long ul_val
 
231
        ul_val = val
 
232
        return self._contains(<int_type>(ul_val))
 
233
 
 
234
    # TODO: Consider that the code would probably be simpler if we just
 
235
    # bit-shifted before passing the value to self._add and self._contains,
 
236
    # rather than re-implementing _lookup here.
215
237
    cdef int_type *_lookup(self, int_type c_val) except NULL:
216
238
        """Taken from the set() algorithm."""
217
239
        cdef size_t offset, perturb