Commit 1899ec28 authored by Xavier Thompson's avatar Xavier Thompson

Implement string __hash__

parent 518f6ec7
......@@ -142,3 +142,8 @@ cdef extern from "<string_view>" namespace "std" nogil:
bint operator>= (const string_view&)
bint operator>= (const char*)
cdef cppclass hash_string_view "std::hash<std::string_view>":
hash_string_view()
size_t operator() (const string_view&)
from stdlib._string cimport string_view
from stdlib._string cimport string_view, hash_string_view
from libc.string cimport strlen, strncpy
from libc.stdlib cimport malloc, free
......@@ -23,6 +23,9 @@ cdef cypclass Str:
bint __eq__(self, Str other):
return self._s == other._s
size_t __hash__(self):
return hash_string_view()(self._s)
char __getitem__(self, int index) except 0:
cdef int end = self._s.size()
cdef int idx = index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment