From 131b86d0d40f0f0dad74e15dedb8c715cfe0518d Mon Sep 17 00:00:00 2001 From: Gary Linscott Date: Fri, 25 Nov 2011 20:21:21 -0500 Subject: [PATCH] Basic implementation of LenPriceTableEncoder --- encoder.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/encoder.js b/encoder.js index 77a428f..966656c 100644 --- a/encoder.js +++ b/encoder.js @@ -252,9 +252,37 @@ function Encoder() { var kNumLenSpecSymbols = kNumLowLenSymbols + kNumMidLenSymbols; + // Derives from LenEncoder this.LenPriceTableEncoder = function() { + var prices = []; + var counters = []; + var tableSize; + this.setTableSize = function(tableSize_) { + tableSize = tableSize_; + }; + + this.updateTable = function(posState) { + this.setPrices(posState, tableSize, prices, posState * kNumLenSymbols); + counters[posState] = tableSize; + }; + + this.updateTables = function(numPosStates) { + var posState; + for (posState = 0; posState < numPosStates; posState++) { + this.updateTable(posState); + } + }; + + this.encode = function(rangeEncoder, symbol, posState) { + this.prototype.encode(rangeEncoder, symbol, posState); + if (--counters[posState] === 0) { + this.updateTable(posState); + } + }; }; + + this.LenPriceTableEncoder.prototype = this.LenEncoder; this.code = function() { var progressPosValuePrev = nowPos;