00001
00002
00003
00004
00005
00006 #ifndef CHARLS_LOOKUPTABLE
00007 #define CHARLS_LOOKUPTABLE
00008
00009
00010
00011 struct Code
00012 {
00013 Code()
00014 {
00015 }
00016
00017 Code(LONG value, LONG length) :
00018 _value(value),
00019 _length(length)
00020 {
00021 }
00022
00023 LONG GetValue() const
00024 { return _value; }
00025 LONG GetLength() const
00026 { return _length; }
00027
00028 LONG _value;
00029 LONG _length;
00030 };
00031
00032
00033
00034 class CTable
00035 {
00036 public:
00037
00038 enum { cbit = 8 } ;
00039
00040 CTable()
00041 {
00042 ::memset(rgtype, 0, sizeof(rgtype));
00043 }
00044
00045 void AddEntry(BYTE bvalue, Code c);
00046
00047 inlinehint const Code& Get(LONG value)
00048 { return rgtype[value]; }
00049 private:
00050 Code rgtype[1 << cbit];
00051 };
00052
00053
00054
00055
00056
00057 void CTable::AddEntry(BYTE bvalue, Code c)
00058 {
00059 LONG length = c.GetLength();
00060 ASSERT(length <= cbit);
00061
00062 for (LONG i = 0; i < LONG(1) << (cbit - length); ++i)
00063 {
00064 ASSERT(rgtype[(bvalue << (cbit - length)) + i].GetLength() == 0);
00065 rgtype[(bvalue << (cbit - length)) + i] = c;
00066 }
00067 }
00068
00069 #endif