2009-09-16 | Paul Boddie | file changeset files shortlog | Added iterator reuse for sequential term dictionary access, along with iterator reuse within position dictionary iteration. A special class, ResetPositionDictionaryIterator, permits the deferred initialisation of iterators, thus preventing their premature reuse and the subsequent loss of results waiting to be read. Fixed imports. Tidied PositionIndexIterator initialisation by moving section_count initialisation into the reset method. |
paul@37 | 1 | #!/usr/bin/env python |
paul@37 | 2 | |
paul@37 | 3 | cdef extern from "Python.h": |
paul@37 | 4 | object PyString_FromStringAndSize(char *, int) |
paul@37 | 5 | |
paul@37 | 6 | def vint(int number): |
paul@37 | 7 | |
paul@37 | 8 | cdef char bytes[40] # NOTE: Arbitrary limit. |
paul@37 | 9 | cdef int lsd, i |
paul@37 | 10 | |
paul@38 | 11 | if number < 128: |
paul@38 | 12 | bytes[0] = number |
paul@38 | 13 | s = PyString_FromStringAndSize(bytes, 1) |
paul@38 | 14 | return s |
paul@38 | 15 | |
paul@37 | 16 | i = 0 |
paul@37 | 17 | while number != 0: |
paul@37 | 18 | lsd = number & 127 |
paul@37 | 19 | number = number >> 7 |
paul@37 | 20 | if number != 0: |
paul@37 | 21 | lsd = lsd | 128 |
paul@37 | 22 | bytes[i] = lsd |
paul@37 | 23 | i = i + 1 |
paul@37 | 24 | |
paul@37 | 25 | s = PyString_FromStringAndSize(bytes, i) |
paul@37 | 26 | return s |
paul@37 | 27 | |
paul@37 | 28 | # vim: tabstop=4 expandtab shiftwidth=4 |