ResetDict will reset and set a dictionary if not nil
(d *dict, singleBlock bool)
| 1051 | |
| 1052 | // ResetDict will reset and set a dictionary if not nil |
| 1053 | func (e *doubleFastEncoderDict) Reset(d *dict, singleBlock bool) { |
| 1054 | allDirty := e.allDirty |
| 1055 | dictChanged := d != e.lastDict |
| 1056 | e.fastEncoderDict.Reset(d, singleBlock) |
| 1057 | if d == nil { |
| 1058 | return |
| 1059 | } |
| 1060 | |
| 1061 | // Init or copy dict table |
| 1062 | if len(e.dictLongTable) != len(e.longTable) || dictChanged { |
| 1063 | if len(e.dictLongTable) != len(e.longTable) { |
| 1064 | e.dictLongTable = make([]tableEntry, len(e.longTable)) |
| 1065 | } else { |
| 1066 | clear(e.dictLongTable) |
| 1067 | } |
| 1068 | if len(d.content) >= 8 { |
| 1069 | cv := load6432(d.content, 0) |
| 1070 | e.dictLongTable[hashLen(cv, dFastLongTableBits, dFastLongLen)] = tableEntry{ |
| 1071 | val: uint32(cv), |
| 1072 | offset: e.maxMatchOff, |
| 1073 | } |
| 1074 | end := int32(len(d.content)) - 8 + e.maxMatchOff |
| 1075 | for i := e.maxMatchOff + 1; i < end; i++ { |
| 1076 | cv = cv>>8 | (uint64(d.content[i-e.maxMatchOff+7]) << 56) |
| 1077 | e.dictLongTable[hashLen(cv, dFastLongTableBits, dFastLongLen)] = tableEntry{ |
| 1078 | val: uint32(cv), |
| 1079 | offset: i, |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | allDirty = true |
| 1084 | } |
| 1085 | // Reset table to initial state |
| 1086 | e.cur = e.maxMatchOff |
| 1087 | |
| 1088 | dirtyShardCnt := 0 |
| 1089 | if !allDirty { |
| 1090 | for i := range e.longTableShardDirty { |
| 1091 | if e.longTableShardDirty[i] { |
| 1092 | dirtyShardCnt++ |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | if allDirty || dirtyShardCnt > dLongTableShardCnt/2 { |
| 1098 | //copy(e.longTable[:], e.dictLongTable) |
| 1099 | e.longTable = *(*[dFastLongTableSize]tableEntry)(e.dictLongTable) |
| 1100 | for i := range e.longTableShardDirty { |
| 1101 | e.longTableShardDirty[i] = false |
| 1102 | } |
| 1103 | return |
| 1104 | } |
| 1105 | for i := range e.longTableShardDirty { |
| 1106 | if !e.longTableShardDirty[i] { |
| 1107 | continue |
| 1108 | } |
| 1109 | |
| 1110 | // copy(e.longTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize], e.dictLongTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize]) |