"""
Template for functions of IndexEngine subclasses.

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

# ----------------------------------------------------------------------
# IndexEngine Subclass Methods
# ----------------------------------------------------------------------

{{py:

# name, dtype, hashtable_name
dtypes = [('Float64', 'float64', 'Float64'),
          ('Float32', 'float32', 'Float64'),
          ('Int64', 'int64', 'Int64'),
          ('Int32', 'int32', 'Int64'),
          ('Int16', 'int16', 'Int64'),
          ('Int8', 'int8', 'Int64'),
          ('UInt64', 'uint64', 'UInt64'),
          ('UInt32', 'uint32', 'UInt64'),
          ('UInt16', 'uint16', 'UInt64'),
          ('UInt8', 'uint8', 'UInt64'),
          ]
}}

{{for name, dtype, hashtable_name in dtypes}}


cdef class {{name}}Engine(IndexEngine):
    # constructor-caller is responsible for ensuring that vgetter()
    #  returns an ndarray with dtype {{dtype}}_t

    cdef _make_hash_table(self, Py_ssize_t n):
        return _hash.{{hashtable_name}}HashTable(n)

    {{if name not in {'Float64', 'Float32'} }}
    cdef _check_type(self, object val):
        if not util.is_integer_object(val):
            raise KeyError(val)
    {{endif}}

    cdef void _call_map_locations(self, values):
        # self.mapping is of type {{hashtable_name}}HashTable,
        # so convert dtype of values
        self.mapping.map_locations(algos.ensure_{{hashtable_name.lower()}}(values))

    cdef _maybe_get_bool_indexer(self, object val):
        cdef:
            ndarray[uint8_t, ndim=1, cast=True] indexer
            ndarray[intp_t, ndim=1] found
            ndarray[{{dtype}}_t, ndim=1] values
            int count = 0

        self._check_type(val)

        values = self._get_index_values()
        try:
            with warnings.catch_warnings():
                # e.g. if values is float64 and `val` is a str, suppress warning
                warnings.filterwarnings("ignore", category=FutureWarning)
                indexer = values == val
        except TypeError:
            # if the equality above returns a bool, cython will raise TypeError
            #  when trying to cast it to ndarray
            raise KeyError(val)

        return self._unpack_bool_indexer(indexer, val)

{{endfor}}
