source: icXML/icXML-devel/src/icxmlc/BitTracker.hpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

File size: 2.1 KB
Line 
1/*
2 *  Copyright © 2012 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icXML is a trademark of International Characters.
5 */
6
7/*
8 * @author Nigel Medforth, nigelm -at- interational-characters.com
9 * @version $Id: BitTracker.hpp 207 2012-12-02 20:38:22Z robc $
10 *
11 */
12
13#ifndef BITTRACKER_HPP
14#define BITTRACKER_HPP
15
16#include <icxmlc/clog2.h>
17#include <simd-lib/bitblock.hpp>
18#include <icxmlc/XMLConfig.hpp>
19
20XERCES_CPP_NAMESPACE_BEGIN
21
22class BitTracker
23{
24public:
25
26        BitTracker();
27
28        BitTracker(const BitTracker & tracker);
29
30        BitTracker& operator=(const BitTracker& tracker);
31
32        void set(const int64_t value);
33
34        bool append(const BitBlock value);
35
36        uint64_t distance();
37
38private:
39
40        BitBlock                      _lastNonEmptyBlock;
41        uint64_t                      _blocksAfterLastNonEmptyBlock;
42};
43
44IDISA_ALWAYS_INLINE
45BitTracker::BitTracker()
46        : _lastNonEmptyBlock(simd<1>::constant<1>())
47        , _blocksAfterLastNonEmptyBlock(0)
48{
49
50}
51
52IDISA_ALWAYS_INLINE
53BitTracker::BitTracker(const BitTracker & tracker)
54        : _lastNonEmptyBlock(tracker._lastNonEmptyBlock)
55        , _blocksAfterLastNonEmptyBlock(tracker._blocksAfterLastNonEmptyBlock)
56{
57
58}
59
60IDISA_ALWAYS_INLINE
61BitTracker& BitTracker::operator=(const BitTracker& tracker)
62{
63        _lastNonEmptyBlock = tracker._lastNonEmptyBlock;
64        _blocksAfterLastNonEmptyBlock = tracker._blocksAfterLastNonEmptyBlock;
65        return *this;
66}
67
68IDISA_ALWAYS_INLINE
69void BitTracker::set(const int64_t value)
70{
71        _blocksAfterLastNonEmptyBlock =
72                value >> LOG_2_BLOCK_SIZE;
73
74        _lastNonEmptyBlock =
75                bitblock::srl(simd<1>::constant<1>(), convert(value & (BLOCK_SIZE - 1)));
76}
77
78IDISA_ALWAYS_INLINE
79bool BitTracker::append(const BitBlock value)
80{
81        if (bitblock::any(value))
82        {
83                _lastNonEmptyBlock = value;
84                _blocksAfterLastNonEmptyBlock = 0;
85                return 1;
86        }
87        else
88        {
89                _blocksAfterLastNonEmptyBlock++;
90                return 0;
91        }
92}
93
94IDISA_ALWAYS_INLINE
95uint64_t BitTracker::distance()
96{
97        return (_blocksAfterLastNonEmptyBlock << LOG_2_BLOCK_SIZE) |
98                   (count_reverse_zeroes(_lastNonEmptyBlock));
99}
100
101XERCES_CPP_NAMESPACE_END
102
103#endif // BITTRACKER_HPP
Note: See TracBrowser for help on using the repository browser.