Skip to content

Commit

Permalink
fix(dict): save/load forward_dimension and backward_dimension of Conn…
Browse files Browse the repository at this point in the history
…ectionCosts to/from cc.dat binary
  • Loading branch information
takuyaa committed Jul 31, 2016
1 parent c98d021 commit 761eaf2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/dict/ConnectionCosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,32 @@
function ConnectionCosts(forward_dimension, backward_dimension) {
this.forward_dimension = forward_dimension;
this.backward_dimension = backward_dimension;
this.buffer = new Int16Array(forward_dimension * backward_dimension);

// leading 2 integers for forward_dimension, backward_dimension, respectively
this.buffer = new Int16Array(forward_dimension * backward_dimension + 2);
this.buffer[0] = forward_dimension;
this.buffer[1] = backward_dimension;
}

ConnectionCosts.prototype.put = function (forward_id, backward_id, cost) {
var index = forward_id * this.backward_dimension + backward_id;
var index = forward_id * this.backward_dimension + backward_id + 2;
if (this.buffer.length < index + 1) {
throw "ConnectionCosts buffer overflow";
}
this.buffer[index] = cost;
};

ConnectionCosts.prototype.get = function (forward_id, backward_id) {
var index = forward_id * this.backward_dimension + backward_id;
var index = forward_id * this.backward_dimension + backward_id + 2;
if (this.buffer.length < index + 1) {
throw "ConnectionCosts buffer overflow";
}
return this.buffer[index];
};

ConnectionCosts.prototype.loadConnectionCosts = function (connection_costs_buffer) {
// TODO Read dimension from connection_costs_buffer
this.forward_dimension = 1316;
this.backward_dimension = 1316;
this.forward_dimension = connection_costs_buffer[0];
this.backward_dimension = connection_costs_buffer[1];
this.buffer = connection_costs_buffer;
};

Expand Down

0 comments on commit 761eaf2

Please sign in to comment.