Skip to content

Commit

Permalink
Switching to obliterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Aug 28, 2017
1 parent d36d126 commit 07a6e9f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 160 deletions.
14 changes: 4 additions & 10 deletions bit-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* - (i >> 5) is the same as ((i / 32) | 0)
* - (i & 0x0000001f) is the sames as (i % 32)
*/
var bitwise = require('./utils/bitwise.js');
var Iterator = require('obliterator/iterator'),
bitwise = require('./utils/bitwise.js');

/**
* BitSet.
Expand Down Expand Up @@ -227,13 +228,6 @@ BitSet.prototype.forEach = function(callback, scope) {
}
};

/**
* Bit Set Iterator class.
*/
function BitSetIterator(next) {
this.next = next;
}

/**
* Method used to create an iterator over a set's values.
*
Expand All @@ -250,7 +244,7 @@ BitSet.prototype.values = function() {
j = -1,
b;

return new BitSetIterator(function next() {
return new Iterator(function next() {
if (!inner) {

if (i >= l)
Expand Down Expand Up @@ -296,7 +290,7 @@ BitSet.prototype.entries = function() {
j = -1,
b;

return new BitSetIterator(function next() {
return new Iterator(function next() {
if (!inner) {

if (i >= l)
Expand Down
17 changes: 1 addition & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,13 @@ Index.prototype.forEach = function(callback, scope) {
});
};


/**
* Index Iterator class.
*/
function IndexIterator(next) {
this.next = next;
}

/**
* Method returning an iterator over the index's values.
*
* @return {IndexIterator}
*/
Index.prototype.values = function() {
var iterator = this.items.values();

Object.defineProperty(iterator, 'constructor', {
value: IndexIterator,
enumerable: false
});

return iterator;
return this.items.values();
};

/**
Expand Down
25 changes: 6 additions & 19 deletions inverted-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
* JavaScript implementation of an inverted index.
*/
var iterateOver = require('./utils/iterate.js'),
var Iterator = require('obliterator/iterator'),
iterateOver = require('./utils/iterate.js'),
helpers = require('./set.js');

function identity(x) {
Expand Down Expand Up @@ -215,24 +216,17 @@ InvertedIndex.prototype.forEach = function(callback, scope) {
callback.call(scope, this.documents[i], i, this);
};

/**
* InvertedIndex Iterator class.
*/
function InvertedIndexIterator(next) {
this.next = next;
}

/**
* Method returning an iterator over the index's documents.
*
* @return {InvertedIndexIterator}
* @return {Iterator}
*/
InvertedIndex.prototype.documents = function() {
var documents = this.items,
l = documents.length,
i = 0;

return new InvertedIndexIterator(function() {
return new Iterator(function() {
if (i >= l)
return {
done: true
Expand All @@ -250,17 +244,10 @@ InvertedIndex.prototype.documents = function() {
/**
* Method returning an iterator over the index's tokens.
*
* @return {InvertedIndexIterator}
* @return {Iterator}
*/
InvertedIndex.prototype.tokens = function() {
var iterator = this.mapping.keys();

Object.defineProperty(iterator, 'constructor', {
value: InvertedIndexIterator,
enumerable: false
});

return iterator;
return this.mapping.keys();
};

/**
Expand Down
14 changes: 4 additions & 10 deletions linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Singly linked list implementation. Uses raw JavaScript objects as nodes
* as benchmarks proved it was the fastest thing to do.
*/
var iterateOver = require('./utils/iterate.js');
var Iterator = require('obliterator/iterator'),
iterateOver = require('./utils/iterate.js');

/**
* Linked List.
Expand Down Expand Up @@ -155,13 +156,6 @@ LinkedList.prototype.toArray = function() {
return array;
};

/**
* Linked List Iterator class.
*/
function LinkedListIterator(next) {
this.next = next;
}

/**
* Method used to create an iterator over a list's values.
*
Expand All @@ -170,7 +164,7 @@ function LinkedListIterator(next) {
LinkedList.prototype.values = function() {
var n = this.head;

return new LinkedListIterator(function() {
return new Iterator(function() {
if (!n)
return {
done: true
Expand All @@ -195,7 +189,7 @@ LinkedList.prototype.entries = function() {
var n = this.head,
i = 0;

return new LinkedListIterator(function() {
return new Iterator(function() {
if (!n)
return {
done: true
Expand Down
16 changes: 1 addition & 15 deletions multi-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,13 @@ MultiIndex.prototype.forEach = function(callback, scope) {
});
};

/**
* MultiIndex Iterator class.
*/
function MultiIndexIterator(next) {
this.next = next;
}

/**
* Method returning an iterator over the index's values.
*
* @return {MultiIndexIterator}
*/
MultiIndex.prototype.values = function() {
var iterator = this.items.values();

Object.defineProperty(iterator, 'constructor', {
value: MultiIndexIterator,
enumerable: false
});

return iterator;
return this.items.values();
};

/**
Expand Down
55 changes: 14 additions & 41 deletions multi-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
* Implementation of a MultiMap with custom container.
*/
var iterateOver = require('./utils/iterate.js');
var Iterator = require('obliterator/iterator'),
iterateOver = require('./utils/iterate.js');

/**
* MultiMap.
Expand Down Expand Up @@ -128,33 +129,19 @@ MultiMap.prototype.forEach = function(callback, scope) {
});
};

/**
* MultiMap Iterator class.
*/
function MultiMapIterator(next) {
this.next = next;
}

/**
* Method returning an iterator over the map's keys.
*
* @return {MultiMapIterator}
* @return {Iterator}
*/
MultiMap.prototype.keys = function() {
var iterator = this.items.keys();

Object.defineProperty(iterator, 'constructor', {
value: MultiMapIterator,
enumerable: false
});

return iterator;
return this.items.keys();
};

/**
* Method returning an iterator over the map's keys.
*
* @return {MultiMapIterator}
* @return {Iterator}
*/
MultiMap.prototype.values = function() {
var iterator = this.items.values(),
Expand All @@ -165,7 +152,7 @@ MultiMap.prototype.values = function() {
l;

if (this.Container === Set)
return new MultiMapIterator(function next() {
return new Iterator(function next() {
if (!inContainer) {
step = iterator.next();

Expand All @@ -189,7 +176,7 @@ MultiMap.prototype.values = function() {
};
});

return new MultiMapIterator(function next() {
return new Iterator(function next() {
if (!inContainer) {
step = iterator.next();

Expand Down Expand Up @@ -217,7 +204,7 @@ MultiMap.prototype.values = function() {
/**
* Method returning an iterator over the map's entries.
*
* @return {MultiMapIterator}
* @return {Iterator}
*/
MultiMap.prototype.entries = function() {
var iterator = this.items.entries(),
Expand All @@ -229,7 +216,7 @@ MultiMap.prototype.entries = function() {
l;

if (this.Container === Set)
return new MultiMapIterator(function next() {
return new Iterator(function next() {
if (!inContainer) {
step = iterator.next();

Expand All @@ -254,7 +241,7 @@ MultiMap.prototype.entries = function() {
};
});

return new MultiMapIterator(function next() {
return new Iterator(function next() {
if (!inContainer) {
step = iterator.next();

Expand Down Expand Up @@ -283,33 +270,19 @@ MultiMap.prototype.entries = function() {
/**
* Method returning an iterator over the map's containers.
*
* @return {MultiMapIterator}
* @return {Iterator}
*/
MultiMap.prototype.containers = function() {
var iterator = this.items.values();

Object.defineProperty(iterator, 'constructor', {
value: MultiMapIterator,
enumerable: false
});

return iterator;
return this.items.values();
};

/**
* Method returning an iterator over the map's associations.
*
* @return {MultiMapIterator}
* @return {Iterator}
*/
MultiMap.prototype.associations = function() {
var iterator = this.items.entries();

Object.defineProperty(iterator, 'constructor', {
value: MultiMapIterator,
enumerable: false
});

return iterator;
return this.items.entries();
};

/**
Expand Down
25 changes: 6 additions & 19 deletions multi-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
* JavaScript implementation of a MultiSet.
*/
var iterateOver = require('./utils/iterate.js');
var Iterator = require('obliterator/iterator'),
iterateOver = require('./utils/iterate.js');

/**
* MultiSet.
Expand Down Expand Up @@ -138,17 +139,10 @@ MultiSet.prototype.forEach = function(callback, scope) {
});
};

/**
* MultiSet Iterator class.
*/
function MultiSetIterator(next) {
this.next = next;
}

/**
* Method returning an iterator over the set's values.
*
* @return {MultiSetIterator}
* @return {Iterator}
*/
MultiSet.prototype.values = function() {
var iterator = this.items.entries(),
Expand All @@ -158,7 +152,7 @@ MultiSet.prototype.values = function() {
multiplicty,
i;

return new MultiSetIterator(function next() {
return new Iterator(function next() {
if (!inContainer) {
step = iterator.next();

Expand Down Expand Up @@ -188,17 +182,10 @@ MultiSet.prototype.values = function() {
/**
* Method returning an iterator over the set's multiplicities.
*
* @return {MultiSetIterator}
* @return {Iterator}
*/
MultiSet.prototype.multiplicities = function() {
var iterator = this.items.entries();

Object.defineProperty(iterator, 'constructor', {
value: MultiSet,
enumerable: false
});

return iterator;
return this.items.entries();
};

/**
Expand Down
Loading

0 comments on commit 07a6e9f

Please sign in to comment.