jsommers / pytricia

A library for fast IP address lookup in Python.
GNU Lesser General Public License v3.0
214 stars 22 forks source link

Extend API to manipulate prefixes #7

Closed zorun closed 8 years ago

zorun commented 8 years ago

Currently, most methods only give access to the values, but not to the keys (prefixes). The new methods implemented here allow to find the longest matching prefix, the parent prefix, and the children prefixes (i.e. all more specific prefixes).

The new methods have been tested with python 2.7 and python 3.4.

This pull request is obviously open to discussions. For instance, children currently returns all children prefixes recursively, but it could also be useful to return only the immediate children (maybe by passing a recursive boolean to the method?).

More generally, it could be interesting to switch to Python to implement complex operations, for instance finding all leaves of a tree, or generating a recursive iterator on children. It would require thinking about the minimum set of basic operations that must be implemented in C.

jsommers commented 8 years ago

Thanks for these suggestions. It may take me some time to get back to this and evaluate the pull request; just wanted to let you know it wasn't being ignored.

jsommers commented 8 years ago

I'm reasonably happy with the pull request as it was. The one thing that might be revisited is the idea of retrieving direct descendants (i.e., not recursively gathering all children), but there's no reason not to merge what's there now.