Ticket #12932: tablestatus.cpp

File tablestatus.cpp, 2.5 KB (added by Roger James <roger@…>, 7 years ago)
Line 
1// -*- Mode: c++ -*-
2// Copyright (c) 2003-2012
3
4#include "tablestatus.h"
5
6#define BIT_SEL(x) (1 << (x))
7
8const uint8_t TableStatus::init_bits[8] = {0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
9
10void TableStatus::InitSections(sections_t &sect, uint32_t last_section)
11{
12    sect.clear();
13
14    uint endz = last_section >> 3;
15    if (endz)
16        sect.resize(endz, 0x00);
17    sect.resize(32, 0xff);
18    sect[endz] = init_bits[last_section & 0x7];
19}
20
21void TableStatus::SetVersion(int32_t version, uint32_t last_section)
22{
23    if (m_version == version)
24        return;
25
26    m_version = version;
27    InitSections(m_sections, last_section);
28}
29
30void TableStatus::SetSectionSeen(int32_t version, uint32_t section,
31                                 uint32_t last_section, uint32_t segment_last_section)
32{
33    SetVersion(version, last_section);
34    m_sections[section>>3] |= BIT_SEL(section & 0x7);
35    if ((segment_last_section != 0xffff) && (last_section != segment_last_section))
36        m_sections[segment_last_section >> 3]
37                   |= init_bits[segment_last_section & 0x7];
38
39}
40
41bool TableStatus::IsSectionSeen(int32_t version, uint32_t section) const
42{
43    if (m_version != version)
44        return false;
45
46    return (bool) (m_sections[section>>3] & BIT_SEL(section & 0x7));
47}
48
49bool TableStatus::HasAllSections() const
50{
51    for (uint32_t i = 0; i < 32; i++)
52        if (m_sections[i] != 0xff)
53            return false;
54    return true;
55}
56
57
58void TableStatusMap::SetVersion(uint64_t key, int32_t version, uint32_t last_section)
59{
60    TableStatus &status = (*this)[key];
61    //NOTE: relies on status.m_version being invalid(-2) if a new entry was just added to the map
62    status.SetVersion(version, last_section);
63}
64
65void TableStatusMap::SetSectionSeen(uint64_t key, int32_t version, uint32_t section,
66                                    uint32_t last_section, uint32_t segment_last_section)
67{
68    TableStatus &status = (*this)[key];
69    //NOTE: relies on status.m_version being invalid(-2) if a new entry was just added to the map
70    status.SetSectionSeen(version, section, last_section, segment_last_section);
71}
72
73bool TableStatusMap::IsSectionSeen(uint64_t key, int32_t version, uint32_t section) const
74{
75    const_iterator it = this->find(key);
76    if (it == this->end() || it->m_version != version)
77        return false;
78    return (bool) (it->m_sections[section>>3] & BIT_SEL(section & 0x7));
79}
80
81bool TableStatusMap::HasAllSections(uint64_t key) const
82{
83    const_iterator it = this->find(key);
84    if (it == this->end())
85        return false;
86
87    return it->HasAllSections();
88}
89