[Cython] Automatic C++ conversions
Robert Bradshaw
robertwb at gmail.com
Mon Jul 2 18:09:00 CEST 2012
On Mon, Jul 2, 2012 at 5:49 AM, Sturla Molden <sturla at molden.no> wrote:
> On 30.06.2012 01:06, Stefan Behnel wrote:
>
>>> std::string<=> bytes
>>> std::map<=> dict
>>> iterable => std::vector => list
>>> iterable => std::list => list
>>> iterable => std::set => set
>>> 2-iterable => std::pair => 2-tuple
>>
>>
>> Very cool.
>
>
> I think (in C++11) std::unordered_set and std::unordered_map should be used
> instead. They are hash-based with O(1) lookup.
>
> std::set and std::map are binary search threes with average O(log n) lookup
> and worst-case O(n**2).
>
> Also beware that C++11 has a std:tuple type.
The object => C++ coercion is always explicit, there's no choice made
here. This is used to do, e.g.
cdef map<int, vector<double>> my_cpp_map = o
or
cdef extern from "mylibrary.h":
cdef map<long, double> my_func(vector<long>)
def f(o):
return my_func(o)
It would make sense to support these unordered versions as well, and
fairly straightforward.
- Robert
More information about the cython-devel
mailing list