intbitset: harmonise pop() behaviour
|Reported by:||simko||Owned by:||Samuele Kaplun <samuele.kaplun@…>|
As mentioned in ticket:621, we may want to improve a little bit the
description and/or behaviour of intbitset's pop(). Notably, people
may be using search engine's API functions returning intbitsets that
look like lists. Here, pop() has ordered meaning for lists, while
for sets it pops any random element:
In : from invenio.intbitset import intbitset In : l = [1, 10, 2, 20] In : s = set(l) In : i = intbitset(l) In : l, s, i Out: ([1, 10, 2, 20], set([1, 10, 20, 2]), intbitset([1, 2, 10, 20])) In : xl, xs, xi = l.pop(), s.pop(), i.pop() In : l, s, i Out: ([1, 10, 2], set([10, 20, 2]), intbitset([2, 10, 20])) In : xl, xs, xi Out: (20, 1, 1)
The difference between lists and intbitsets is strictly taken OK,
because intbitsets emulate the API of sets, so pop() removes an
arbitrary set element. However, behind the scenes intbitset's pop()
calls intBitSetGetNext() that does an ordered removal, not an
"arbitrary" removal; so we can document this better for end users.
More to the point, intbitset has a native notion of element order,
being a set of increasing integers; it does resemble ordered lists of
integers in this respect. intbitset can be considered as a kind of
ordered set of increasing integers that emulates set API, so having
some facets of lists and some facets of sets, as it were.
Therefore we may want to improve the docstring of intbitset's pop()
in order to reflect this mixed nature of intbitsets: (i) at least by
documenting the non-arbitrary parts, but (ii) more to the point, we
may want to alter perhaps the meaning of what pop() returns, so that
intbitset would resemble lists more (i.e. returning last, not first
element). It will still be an "arbitrary" removal from the set API
point of view, but it will resemble more to what people may be used to
from the list API point of view, if they think of intbitsets as of
lists of increasing integers.
P.S. Not thinking here about list-specific calls like pop(n).
Change History (7)
comment:2 Changed 22 months ago by Samuele Kaplun <samuele.kaplun@…>
- Owner set to Samuele Kaplun <samuele.kaplun@…>
- Resolution set to fixed
- Status changed from new to closed