Coverage Report

Created: 2023-12-08 06:59

/src/aspell/common/hash_fun.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2001
2
// Kevin Atkinson
3
//
4
// Permission to use, copy, modify, distribute and sell this software
5
// and its documentation for any purpose is hereby granted without
6
// fee, provided that the above copyright notice appear in all copies
7
// and that both that copyright notice and this permission notice
8
// appear in supporting documentation. Kevin Atkinson makes no
9
// representations about the suitability of this software for any
10
// purpose.  It is provided "as is" without express or implied
11
// warranty.
12
13
#ifndef acommon_hash_fun__hpp
14
#define acommon_hash_fun__hpp
15
16
namespace acommon {
17
  
18
  template <typename K> struct hash {};
19
20
0
  template <> struct hash<char>  {unsigned long operator()(char  v) const {return v;}};
21
0
  template <> struct hash<short> {unsigned long operator()(short v) const {return v;}};
22
0
  template <> struct hash<int>   {unsigned long operator()(int   v) const {return v;}};
23
0
  template <> struct hash<long>  {unsigned long operator()(long  v) const {return v;}};
24
0
  template <> struct hash<unsigned char>  {unsigned long operator()(unsigned char  v) const {return v;}};
25
0
  template <> struct hash<unsigned short> {unsigned long operator()(unsigned short v) const {return v;}};
26
0
  template <> struct hash<unsigned int>   {unsigned long operator()(unsigned int   v) const {return v;}};
27
0
  template <> struct hash<unsigned long>  {unsigned long operator()(unsigned long  v) const {return v;}};
28
29
  template <> struct hash<const char *> {
30
19.3M
    inline unsigned long operator() (const char * s) const {
31
19.3M
      unsigned long h = 0;
32
119M
      for (; *s; ++s)
33
100M
  h=5*h + *s;
34
19.3M
      return h;
35
19.3M
    }
36
  };
37
38
  template<class Str>
39
  struct HashString {
40
    inline unsigned long operator() (const Str &str) const {
41
      unsigned long h = 0;
42
      typename Str::const_iterator end = str.end();
43
      for (typename Str::const_iterator s = str.begin(); 
44
     s != end; 
45
     ++s)
46
  h=5*h + *s;
47
      return h;
48
    }
49
  };
50
  
51
}
52
53
#endif