This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// entropy.js MIT License © 2014 James Abney http://github.com/jabney | |
/*************************************** | |
* ES2015 | |
***************************************/ | |
// Shannon entropy in bits per symbol. | |
function entropy(str) { | |
const len = str.length | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declare.js MIT License © 2014 James Abney http://github.com/jabney | |
// An experiment with "forward type checking". Register types | |
// using 'declare' along with corresponding methods. The methods | |
// get called depending upon the type of the passed object. | |
// | |
// // Create a new declare object. | |
// var logByType = fwdType.declare(); | |
// | |
// // Register types and methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// encode.js MIT License © 2014 James Abney http://github.com/jabney | |
// Encode built-in type as a numeric value. | |
// | |
// typeOf(null); // => 'Null' | |
// typeOf(undefined); // => 'Undefined' | |
// typeOf([]); // => 'Array' | |
// | |
// encodeType(null); // => 1 | |
// encodeType(undefined); // => 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setOps.js MIT License © 2014 James Abney http://github.com/jabney | |
// Set operations union, intersection, symmetric difference, | |
// relative complement, equals. Set operations are fast. | |
(function(so) { | |
'use strict'; | |
var uidList = [], uid; | |
// Create and push the uid identity method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shuffle.js © 2014 James Abney http://github.com/jabney | |
(function(ex) { | |
'use strict'; | |
// Export shuffle to 'random' namespace. | |
var random = ex.random || (ex.random = Object.create(null)); | |
// Shuffle an array in place so that the positions of its values are random. | |
random.shuffle = function shuffle(a) { | |
var i, r, tmp, len = a.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PriorityQueue.js MIT License © 2014 James Abney http://github.com/jabney | |
(function(ex) { | |
'use strict'; | |
// --------------------------------------------------------------- | |
// PriorityQueue Constructor | |
// A heap-based priority queue. | |
// --------------------------------------------------------------- | |
ex.PriorityQueue = function PriorityQueue(compare) { | |
var compare = compare || function(a, b) { return a < b; }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// huffman.js © 2014 James Abney http://github.com/jabney | |
// Huffman coding was invented by David A. Huffman of MIT, 1952. | |
(function() { | |
'use strict'; | |
// A toy implementation of Huffman compression. The result of | |
// encoding is a bit string. In this form it's not truly compressed, | |
// but the bit string represents the binary values after compression. | |
function huffman(str) { | |
var ft = frequencyTable(str), ht = huffTree(ft); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// graph.js © 2015 James Abney http://github.com/jabney | |
(function(ex, undefined) { | |
'use strict'; | |
var gr = ex.graph || (ex.graph = Object.create(null)); | |
// --------------------------------------------------------------- | |
// The graph abstract data type. | |
// --------------------------------------------------------------- | |
gr.graph = function graph(numVerts) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
containers.js | |
MIT License © 2015 James Abney | |
http://github.com/jabney | |
Containers: bag, stack, queue, double-ended queue (deque), | |
priorityQueue, and set. | |
See documentation at http://github.com/jabney/containers.js | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This augmentation style is appropriate for a factory-style function, | |
// which might be something that was imported as part of a library. | |
var factory = function factory() { | |
var data = []; | |
// Return an object with one or more methods. | |
return { | |
init: function() { | |
data.push.apply(data, arguments); |
OlderNewer