Giter VIP home page Giter VIP logo

Comments (1)

jamadden avatar jamadden commented on July 18, 2024

In the C extension, slices are implemented by just returning a new Items object, just like a plain call to keys():

>>> a.keys()
<OOBTreeItems at 0x11084fc40>
>>> a.keys()[1:2]
<OOBTreeItems at 0x10fcc2ee0>

That object uses the same underlying bucket storage as the tree, and it doesn't have any place to store the extra state needed to track a different step size, so that's the first problem.

More serious, though, is that BTreeItems support indexed subscripting of themselves:

>>> bt = OOBTree()
>>> bt['a'] = 1
>>> bt.keys()[0]
'a'

They implement iteration using that subscripting support through the old iteration protocol. So the object would have to be changed to understand how to compute "real" indexes based on a different step size, which sounds like it could get ugly.

I'll note that the Python implementation just punts the whole problem over to list for any slice:

>>> from BTrees.OOBTree import OOBTreePy
>>> a = OOBTreePy({1:"one", 2:"two", 3:"three"})
>>> a.keys()
<BTrees._base._TreeItems object at 0x1026fb858>
>>> a.keys()[1:2]
[2]

That loads the whole tree into memory, though, which is not efficient. But it works (for small cases...) and probably wouldn't be that hard to adopt in C if we wanted to. (Either that or the Python implementation should enforce the same restriction.)

from btrees.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.