
"""
Template for sets

WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
"""

include "set_init.pxi"

{{py:

# set_name, name, key_type, c_key_type
set_types       = [('Int64', 'int64', 'int64_t', 'int64_t'),
                   ('Float64', 'float64', 'float64_t' , 'float64_t'),
                   ('Int32', 'int32', 'int32_t', 'int32_t'),
                   ('Float32', 'float32', 'float32_t', 'float32_t'),
                   ('PyObject', 'pyobject', 'object', 'pyobject_t'),
                  ]
}}


{{for set_name, name, key_type, c_key_type in set_types}}


cdef extern from *:

    ctypedef struct kh_{{name}}set_t:
        khint_t n_buckets, size, n_occupied, upper_bound
        uint32_t *flags
        {{c_key_type}} *keys
        #size_t *vals  //dummy

    kh_{{name}}set_t* kh_init_{{name}}set() nogil
    void kh_destroy_{{name}}set(kh_{{name}}set_t*) nogil
    void kh_clear_{{name}}set(kh_{{name}}set_t*) nogil
    khint_t kh_get_{{name}}set(kh_{{name}}set_t*, {{c_key_type}}) nogil
    void kh_resize_{{name}}set(kh_{{name}}set_t*, khint_t) nogil
    khint_t kh_put_{{name}}set(kh_{{name}}set_t*, {{c_key_type}}, int*) nogil
    void kh_del_{{name}}set(kh_{{name}}set_t*, khint_t) nogil

    #specializing "kh_exist"-macro 
    bint kh_exist_{{name}}set "kh_exist" (kh_{{name}}set_t*, khint_t) nogil


cdef class {{set_name}}Set:
    cdef kh_{{name}}set_t *table

    cdef bint contains(self, {{key_type}} key) except *
    cdef {{set_name}}SetIterator get_iter(self)
    cdef khint_t size(self) 
    cpdef void add(self, {{key_type}} key) except *
    cpdef void discard(self, {{key_type}} key) except *
    

cdef class {{set_name}}SetIterator:
    cdef khint_t   it
    cdef {{set_name}}Set  parent

    cdef bint has_next(self) except *
    {{if set_name == 'PyObject'}}
    cdef {{key_type}} next(self)
    {{else}}
    cdef {{key_type}} next(self) except *
    {{endif}}
    cdef void __move(self) except *


cpdef {{set_name}}Set {{set_name}}Set_from_buffer({{key_type}}[:] buf, double size_hint=*)


from libc.stdint cimport  uint8_t
cpdef void isin_{{name}}({{key_type}}[:] query, {{set_name}}Set db, uint8_t[:] result) except *

cpdef bint all_{{name}}({{key_type}}[:] query, {{set_name}}Set db) except *
cpdef bint all_{{name}}_from_iter(object query, {{set_name}}Set db) except *

cpdef bint none_{{name}}({{key_type}}[:] query, {{set_name}}Set db) except *
cpdef bint none_{{name}}_from_iter(object query, {{set_name}}Set db) except *

cpdef bint any_{{name}}({{key_type}}[:] query, {{set_name}}Set db) except *
cpdef bint any_{{name}}_from_iter(object query, {{set_name}}Set db) except *

cpdef size_t count_if_{{name}}({{key_type}}[:] query, {{set_name}}Set db) except *
cpdef size_t count_if_{{name}}_from_iter(object query, {{set_name}}Set db) except *

cpdef void swap_{{name}}({{set_name}}Set a, {{set_name}}Set b) except *

# for drop-in replacements:
cpdef bint aredisjoint_{{name}}({{set_name}}Set a, {{set_name}}Set b) except *
cpdef bint issubset_{{name}}({{set_name}}Set s, {{set_name}}Set sub) except *
cpdef {{set_name}}Set copy_{{name}}({{set_name}}Set s)
cpdef void update_{{name}}({{set_name}}Set s, {{set_name}}Set other) except *
cpdef {{set_name}}Set intersect_{{name}}({{set_name}}Set a, {{set_name}}Set b)
cpdef {{set_name}}Set difference_{{name}}({{set_name}}Set a, {{set_name}}Set b)
cpdef {{set_name}}Set symmetric_difference_{{name}}({{set_name}}Set a, {{set_name}}Set b)


{{endfor}}
