Embedded Template Library  1.0
jenkins.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2014 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_JENKINS_INCLUDED
32 #define ETL_JENKINS_INCLUDED
33 
34 #include <stdint.h>
35 
36 #include "platform.h"
37 #include "static_assert.h"
38 #include "type_traits.h"
39 #include "error_handler.h"
40 #include "ihash.h"
41 #include "frame_check_sequence.h"
42 
43 #include "iterator.h"
44 
45 #if defined(ETL_COMPILER_KEIL)
46 #pragma diag_suppress 1300
47 #endif
48 
51 
52 namespace etl
53 {
54  //***************************************************************************
57  //***************************************************************************
59  {
60  typedef uint32_t value_type;
61 
62  inline uint32_t initial() const
63  {
64  is_finalised = false;
65 
66  return 0;
67  }
68 
69  inline uint32_t add(value_type hash, uint8_t value) const
70  {
71  ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised));
72 
73  hash += value;
74  hash += (hash << 10);
75  hash ^= (hash >> 6);
76 
77  return hash;
78  }
79 
80  inline uint32_t final(value_type hash) const
81  {
82  hash += (hash << 3);
83  hash ^= (hash >> 11);
84  hash += (hash << 15);
85  is_finalised = true;
86 
87  return hash;
88  }
89 
90  mutable bool is_finalised;
91  };
92 
93  //*************************************************************************
95  //*************************************************************************
96  class jenkins : public etl::frame_check_sequence<etl::jenkins_policy>
97  {
98  public:
99 
100  //*************************************************************************
102  //*************************************************************************
104  {
105  this->reset();
106  }
107 
108  //*************************************************************************
112  //*************************************************************************
113  template<typename TIterator>
114  jenkins(TIterator begin, const TIterator end)
115  {
116  this->reset();
117  this->add(begin, end);
118  }
119  };
120 }
121 
122 #endif
jenkins
Definition: jenkins.h:97
jenkins()
Default constructor.
Definition: jenkins.h:103
jenkins(TIterator begin, const TIterator end)
Definition: jenkins.h:114
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: container.h:49
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: container.h:99
#define ETL_ASSERT(b, e)
Definition: error_handler.h:290
void reset()
Resets the FCS to the initial state.
Definition: frame_check_sequence.h:135
void add(TIterator begin, const TIterator end)
Definition: frame_check_sequence.h:146
Definition: frame_check_sequence.h:101
Definition: hash.h:93
Definition: ihash.h:69
Definition: absolute.h:37
Definition: jenkins.h:59