Lolly 1.4.28
Loading...
Searching...
No Matches
hashfunc.hpp
Go to the documentation of this file.
1/** \file hashfunc.hpp
2 * \copyright GPLv3
3 * \details This hashfunc is a generic hash function class that utilizes a
4 * concrete implementation of a hash function for a given type.
5 * \author Joris van der Hoeven
6 * \date 1999
7 */
8
9#ifndef HASHFUNC_H
10#define HASHFUNC_H
11#include "hashmap.hpp"
12
13/**
14 * @brief A concrete implementation of a hash function for a given type.
15 * @tparam T The input type of the hash function.
16 * @tparam U The output type of the hash function.
17 */
18template <class T, class U> class hashfunc_rep : public concrete_struct {
19 U (*func) (T); /**< A pointer to the hash function. */
20 hashmap<T, U> remember; /**< A hash map to store remembered values. */
21public:
22 /**
23 * @brief Constructor for hashfunc_rep.
24 * @param func2 A pointer to the hash function to be used.
25 * @param init The initial value for the hash map.
26 */
27 inline hashfunc_rep (U (*func2) (T), U init)
28 : func (func2), remember (init) {}
29
30 /**
31 * @brief Applies the hash function to the given input.
32 * @param x The input value to be hashed.
33 * @return The output of the hash function for the given input.
34 */
35 U apply (T x);
36};
37
38/**
39 * @brief A generic hash function class that uses a concrete implementation of a
40 * hash function.
41 * @tparam T The input type of the hash function.
42 * @tparam U The output type of the hash function.
43 */
44template <class T, class U> class hashfunc {
46
47 /**
48 * @brief Constructor for hashfunc.
49 * @param func A pointer to the hash function to be used.
50 * @param init The initial value for the hash map.
51 */
52 inline hashfunc (U (*func) (T), U init)
53 : rep (tm_new<hashfunc_rep<T, U>> (func, init)) {}
54
55 /**
56 * @brief Applies the hash function to the given input.
57 * @param x The input value to be hashed.
58 * @return The output of the hash function for the given input.
59 */
60 inline U operator[] (T x) { return rep->apply (x); }
61};
62CONCRETE_TEMPLATE_2_CODE (hashfunc, class, T, class, U);
63
64#include "hashfunc.ipp"
65
66#endif // defined HASHFUNC_H
#define CONCRETE_TEMPLATE_2_CODE(PTR, TT1, T1, TT2, T2)
Macro used to define the implementation of a concrete smart pointer with reference counting for two t...
Definition classdef.hpp:278
A concrete implementation of a hash function for a given type.
Definition hashfunc.hpp:18
hashfunc_rep(U(*func2)(T), U init)
Constructor for hashfunc_rep.
Definition hashfunc.hpp:27
U apply(T x)
Applies the hash function to the given input.
Definition hashfunc.ipp:18
U(* func)(T)
Definition hashfunc.hpp:19
hashmap< T, U > remember
Definition hashfunc.hpp:20
A generic hash function class that uses a concrete implementation of a hash function.
Definition hashfunc.hpp:44
U operator[](T x)
Applies the hash function to the given input.
Definition hashfunc.hpp:60
hashfunc(U(*func)(T), U init)
Constructor for hashfunc.
Definition hashfunc.hpp:52
CONCRETE_TEMPLATE_2(hashfunc, T, U)
The list class represents a linked list.
Definition list.hpp:48
C * tm_new()
Structure representing a concrete object with a reference count.
Definition classdef.hpp:24
base class of resources
Definition resource.hpp:23