2 var Words = Collection.extend({
\r
3 constructor: function(script) {
\r
5 forEach (script.match(WORDS), this.add, this);
\r
9 add: function(word) {
\r
10 if (!this.exists(word)) this.base(word);
\r
11 word = this.fetch(word);
\r
16 encode: function() {
\r
17 // sort by frequency
\r
18 this.sort(function(word1, word2) {
\r
19 return word2.count - word1.count;
\r
22 eval("var a=62,e=" + Packer.ENCODE62);
\r
24 var encoded = new Collection; // a dictionary of base62 -> base10
\r
25 var count = this.count();
\r
26 for (var i = 0; i < count; i++) {
\r
27 encoded.store(encode(i), i);
\r
30 var empty = function() {return ""};
\r
32 forEach (this, function(word) {
\r
33 if (encoded.exists(word)) {
\r
34 word.index = encoded.fetch(word);
\r
35 word.toString = empty;
\r
37 while (this.exists(encode(index))) index++;
\r
38 word.index = index++;
\r
40 word.encoded = encode(word.index);
\r
44 this.sort(function(word1, word2) {
\r
45 return word1.index - word2.index;
\r
49 toString: function() {
\r
50 return this.values().join("|");
\r
54 constructor: function(word) {
\r
55 this.toString = function() {return word};
\r