mikpom / rbi_tree

Cython-wrapped C++ red-black interval tree implementation
0 stars 0 forks source link

Support for uint64_t #2

Open IridiumXOR opened 3 years ago

IridiumXOR commented 3 years ago

Hi, the Cython port supports only int as values but it is very useful to have the support for uint64_t (for example, in my case, to use the library to store 64-bit virtual addresses). I have modified the pyx file replacing all the int with uint64_t (and it works!) but it will be more useful to have the possibility to chose the integer class to pass to the C++ library. Here it is explained how to pass generic type from Python to C++ https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html

mikpom commented 3 years ago

Hi @IridiumXOR ,

Overcoming the limitation of int in interval definition is something I was thinking of. I'll have a look if some implementation is feasible.

NiklasBeierl commented 3 years ago

I was gonna try putting virtual addresses into here as well. Not much of a C Programmer, but lemme know if I can help.

@IridiumXOR care to share what you are working on? I am working on memory forensics as well. (IT Student from Germany).

IridiumXOR commented 3 years ago

I was gonna try putting virtual addresses into here as well. Not much of a C Programmer, but lemme know if I can help.

@IridiumXOR care to share what you are working on? I am working on memory forensics as well. (IT Student from Germany).

Oh nice! This library however is needed for a personal project unrelated to work :)

mikpom commented 3 years ago

Hi @IridiumXOR

At a first glance I thought you need large intergers as interval borders (this is what was my comment above about). But looks like you need it as values. Class ITree supports arbitrary python objects as interval values. Python doesn't have any limitation on int size as you can see from snippet below:

from rbi_tree.tree import ITree
import math

max_uint64 = int(math.pow(2, 64))

really_yuge_integers = [max_uint64+i for i in range(10)]

t = ITree()    
for i, integer in zip(range(10), really_yuge_integers):
    t.insert(i, i+1, integer)

print(t.find_at(5)[0])

it gives

(5, 6, 18446744073709551621)

I think you don't need to hack with .pyx file