Socket
Socket
Sign inDemoInstall

cnd

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cnd - npm Package Compare versions

Comparing version 1.0.9 to 2.0.2

lib/INTERSKIPLIST.js

67

lib/BITSNPIECES.js

@@ -1,4 +0,4 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {
var LODASH, njs_fs, njs_path, njs_util, permute, rpr, validate_isa_number,
var CND, LODASH, njs_fs, njs_path, njs_util, permute, rpr, validate_isa_number,
slice = [].slice;

@@ -20,2 +20,4 @@

CND = require('./main');
this.equals = function() {

@@ -704,46 +706,29 @@ var P, arity;

this.size_of = function(x) {
return this._size_of(x, new Map());
};
this._size_of = function(x, seen) {
var CND, R, type;
CND = require('./main');
R = 0;
if (seen.has(x)) {
return R;
}
seen.set(x, 1);
this.size_of = function(x, settings) {
var ref, ref1, selector, type;
switch (type = CND.type_of(x)) {
case 'boolean':
R += 4;
break;
case 'null':
case 'jsundefined':
case 'jsnan':
R += 1;
break;
case 'list':
case 'arguments':
case 'buffer':
return x.length;
case 'text':
case 'jsbuffer':
R += x.length * 2;
switch (selector = (ref = settings != null ? settings['count'] : void 0) != null ? ref : 'codeunits') {
case 'codepoints':
return (Array.from(x)).length;
case 'codeunits':
return x.length;
case 'bytes':
return Buffer.byteLength(x, (ref1 = settings != null ? settings['encoding'] : void 0) != null ? ref1 : 'utf-8');
default:
throw new Error("unknown counting selector " + (rpr(selector)));
}
break;
case 'number':
R += 8;
break;
default:
R += this._size_of_container(x, seen);
case 'set':
case 'map':
return x.size;
}
return R;
};
this._size_of_container = function(x, seen) {
var R, i, key, len, ref;
seen.set(x, 1);
R = 0;
ref = Object.keys(x);
for (i = 0, len = ref.length; i < len; i++) {
key = ref[i];
R += this._size_of(x[key], seen);
if (CND.isa_pod(x)) {
return (Object.keys(x)).length;
}
return R;
throw new Error("unable to get size of a " + type);
};

@@ -750,0 +735,0 @@

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -3,0 +3,0 @@ this.new_filter = function(settings) {

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3

@@ -3,0 +3,0 @@ /* LIST methods */

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -17,3 +17,3 @@ var i, len, method_count, module, name, njs_util, ref, route, routes, rpr, value;

this.INTERVALTREE = require('./INTERVALTREE');
this.INTERSKIPLIST = require('./INTERSKIPLIST');

@@ -20,0 +20,0 @@ method_count = 0;

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -3,0 +3,0 @@ var slice = [].slice;

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {
var BNP, TRM, alert, assert, badge, debug, echo, help, info, log, njs_path, praise, rpr, urge, warn, whisper,
slice = [].slice;
var CND, SL, TRM, alert, badge, debug, echo, help, include, info, log, njs_path, praise, rpr, test, urge, warn, whisper,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

@@ -34,45 +34,167 @@ njs_path = require('path');

assert = require('assert');
CND = require('./main');
BNP = require('./main');
SL = CND.INTERSKIPLIST;
this.test = {
ok: (function(_this) {
return function(result) {
test = require('guy-test');
/* Tests whether `result` is strictly `true` (not only true-ish). */
if (result !== true) {
throw new Error("expected true, got\n" + (rpr(result)));
}
};
})(this),
fail: (function(_this) {
return function(message) {
throw new Error(message);
};
})(this),
eq: (function(_this) {
return function() {
var P, i, len, p, values;
P = 1 <= arguments.length ? slice.call(arguments, 0) : [];
this['test interval tree 1'] = function(T) {
var find, hi, i, id, intervals, len, lo, ref, skiplist, value;
find = function(skiplist, probe) {
var R;
R = SL.find_any_ids(skiplist, probe);
R.sort();
return R.join(',');
};
skiplist = SL["new"]();
intervals = [[1, 3, 'A'], [2, 14, 'B'], [3, 7, 'C'], [4, 4, 'D'], [5, 7, 'E'], [8, 12, 'F1'], [8, 12, 'F2'], [8, 22, 'G'], [10, 13, 'H']];
for (i = 0, len = intervals.length; i < len; i++) {
ref = intervals[i], lo = ref[0], hi = ref[1], id = ref[2], value = ref[3];
SL.add_interval(skiplist, lo, hi, id, value);
}
T.eq(find(skiplist, 0), '');
T.eq(find(skiplist, 1), 'A');
T.eq(find(skiplist, 2), 'A,B');
T.eq(find(skiplist, 3), 'A,B,C');
T.eq(find(skiplist, 4), 'B,C,D');
T.eq(find(skiplist, 5), 'B,C,E');
T.eq(find(skiplist, 6), 'B,C,E');
T.eq(find(skiplist, 7), 'B,C,E');
T.eq(find(skiplist, 8), 'B,F1,F2,G');
T.eq(find(skiplist, 9), 'B,F1,F2,G');
T.eq(find(skiplist, 10), 'B,F1,F2,G,H');
T.eq(find(skiplist, 11), 'B,F1,F2,G,H');
T.eq(find(skiplist, 12), 'B,F1,F2,G,H');
T.eq(find(skiplist, 13), 'B,G,H');
T.eq(find(skiplist, 14), 'B,G');
T.eq(find(skiplist, 15), 'G');
T.eq(find(skiplist, 16), 'G');
T.eq(find(skiplist, 17), 'G');
T.eq(find(skiplist, 18), 'G');
return null;
};
/* Tests whether all arguments are pairwise and deeply equal. Uses CoffeeNode Bits'n'Pieces' `equal`
for testing as (1) Node's `assert` distinguishes—unnecessarily—between shallow and deep equality, and,
worse, [`assert.equal` and `assert.deepEqual` are broken](https://github.com/joyent/node/issues/7161),
as they use JavaScript's broken `==` equality operator instead of `===`.
*/
values = [];
for (i = 0, len = P.length; i < len; i++) {
p = P[i];
_this["new"]._delete_grammar_references(p);
values.push(rpr(p));
}
if (!BNP.equals.apply(BNP, P)) {
throw new Error("not equal: \n" + (values.join('\n')));
}
};
})(this),
throws: assert.throws.bind(assert)
this['_test interval tree 2'] = function() {
var error_count, i, interval, intervals, len, tree;
tree = SL.new_tree();
intervals = [[17, 19, 'A'], [5, 8, 'B'], [21, 24, 'C'], [4, 8, 'D'], [15, 18, 'E'], [7, 10, 'F'], [16, 22, 'G']];
for (i = 0, len = intervals.length; i < len; i++) {
interval = intervals[i];
SL.add_interval(tree, interval);
}
SL._decorate(tree['%self']['root']);
show(tree['%self']['root']);
error_count = 0;
debug(rpr(find(tree, [8, 9])));
debug(rpr(find(tree, [5, 8])));
debug(rpr(find(tree, [21, 24])));
debug(rpr(find(tree, [4, 8])));
if (error_count !== 0) {
throw Error("there were " + error_count + " errors");
}
return null;
};
this['test type_of'] = function(T) {
T.eq(CND.type_of(new WeakMap()), 'weakmap');
T.eq(CND.type_of(new Map()), 'map');
T.eq(CND.type_of(new Set()), 'set');
T.eq(CND.type_of(new Date()), 'date');
T.eq(CND.type_of(new Error()), 'error');
T.eq(CND.type_of([]), 'list');
T.eq(CND.type_of(true), 'boolean');
T.eq(CND.type_of(false), 'boolean');
T.eq(CND.type_of((function() {})), 'function');
T.eq(CND.type_of((function*() {
return (yield 123);
})()), 'generator');
T.eq(CND.type_of(null), 'null');
T.eq(CND.type_of('helo'), 'text');
T.eq(CND.type_of(void 0), 'undefined');
T.eq(CND.type_of(arguments), 'arguments');
T.eq(CND.type_of(global), 'global');
T.eq(CND.type_of(/^xxx$/g), 'regex');
T.eq(CND.type_of({}), 'pod');
T.eq(CND.type_of(NaN), 'nan');
T.eq(CND.type_of(1 / 0), 'infinity');
T.eq(CND.type_of(-1 / 0), 'infinity');
T.eq(CND.type_of(12345), 'number');
T.eq(CND.type_of(new Buffer('helo')), 'buffer');
T.eq(CND.type_of(new ArrayBuffer(42)), 'arraybuffer');
return null;
};
this['test size_of'] = function(T) {
T.eq(CND.size_of([1, 2, 3, 4]), 4);
T.eq(CND.size_of(new Buffer([1, 2, 3, 4])), 4);
T.eq(CND.size_of('𣁬𡉜𠑹𠅁'), 2 * (Array.from('𣁬𡉜𠑹𠅁')).length);
T.eq(CND.size_of('𣁬𡉜𠑹𠅁', {
count: 'codepoints'
}), (Array.from('𣁬𡉜𠑹𠅁')).length);
T.eq(CND.size_of('𣁬𡉜𠑹𠅁', {
count: 'codeunits'
}), 2 * (Array.from('𣁬𡉜𠑹𠅁')).length);
T.eq(CND.size_of('𣁬𡉜𠑹𠅁', {
count: 'bytes'
}), (new Buffer('𣁬𡉜𠑹𠅁', 'utf-8')).length);
T.eq(CND.size_of('abcdefghijklmnopqrstuvwxyz'), 26);
T.eq(CND.size_of('abcdefghijklmnopqrstuvwxyz', {
count: 'codepoints'
}), 26);
T.eq(CND.size_of('abcdefghijklmnopqrstuvwxyz', {
count: 'codeunits'
}), 26);
T.eq(CND.size_of('abcdefghijklmnopqrstuvwxyz', {
count: 'bytes'
}), 26);
T.eq(CND.size_of('ä'), 1);
T.eq(CND.size_of('ä', {
count: 'codepoints'
}), 1);
T.eq(CND.size_of('ä', {
count: 'codeunits'
}), 1);
T.eq(CND.size_of('ä', {
count: 'bytes'
}), 2);
T.eq(CND.size_of(new Map([['foo', 42], ['bar', 108]])), 2);
T.eq(CND.size_of(new Set(['foo', 42, 'bar', 108])), 4);
T.eq(CND.size_of({
'foo': 42,
'bar': 108,
'baz': 3
}), 3);
return T.eq(CND.size_of({
'~isa': 'XYZ/yadda',
'foo': 42,
'bar': 108,
'baz': 3
}), 4);
};
this._main = function(handler) {
return test(this, {
'timeout': 2500
});
};
this._prune = function() {
var name, value;
for (name in this) {
value = this[name];
if (name.startsWith('_')) {
continue;
}
if (indexOf.call(include, name) < 0) {
delete this[name];
}
}
return null;
};
if (module.parent == null) {
include = ['test type_of'];
this._main();
}
}).call(this);

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -3,0 +3,0 @@ this.blink = "\x1b[5m";

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -3,0 +3,0 @@ var CND, ansi_vt100_cc_matcher, rgb_hex_by_vt100_colorcode;

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -3,0 +3,0 @@ var TYPES, _rpr, badge, color_code, color_name, effect_name, effect_names, effect_off, effect_on, fn, fn1, isa_text, lines_from_stdout, rainbow_color_names, rainbow_idx, ref,

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3

@@ -3,0 +3,0 @@ /* Adapted from https://github.com/eknkc/tsort */

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -25,19 +25,16 @@ var isBuffer, js_type_of, log, njs_util, ref, rpr,

'[object Array]': 'list',
'[object Boolean]': 'boolean',
'[object Function]': 'function',
'[object Null]': 'null',
'[object String]': 'text',
'[object Generator]': 'generator',
'[object Undefined]': 'jsundefined',
'[object Arguments]': 'jsarguments',
'[object Date]': 'jsdate',
'[object Error]': 'jserror',
'[object global]': 'jsglobal',
'[object RegExp]': 'jsregex',
'[object DOMWindow]': 'jswindow',
'[object CanvasRenderingContext2D]': 'jsctx',
'[object ArrayBuffer]': 'jsarraybuffer',
'[object Arguments]': 'arguments',
'[object Date]': 'date',
'[object Error]': 'error',
'[object global]': 'global',
'[object RegExp]': 'regex',
'[object DOMWindow]': 'window',
'[object CanvasRenderingContext2D]': 'canvasrenderingcontext2d',
'[object ArrayBuffer]': 'arraybuffer',
'[object Object]': function(x) {
if (isBuffer(x)) {
return 'jsbuffer';
return 'buffer';
}

@@ -50,7 +47,4 @@ return 'pod';

if (isNaN(x)) {
return 'jsnotanumber';
return 'nan';
}
if (x === Infinity || x === -Infinity) {
return 'jsinfinity';
}
return 'number';

@@ -63,8 +57,14 @@ }

var R, js_type;
if (x === null) {
return 'null';
switch (x) {
case null:
return 'null';
case void 0:
return 'undefined';
case true:
case false:
return 'boolean';
case -Infinity:
case Infinity:
return 'infinity';
}
if (x === void 0) {
return 'jsundefined';
}
R = x['~isa'];

@@ -74,6 +74,9 @@ if (R != null) {

}
if (Buffer.isBuffer(x)) {
return 'buffer';
}
js_type = js_type_of(x);
R = this._coffeenode_type_by_js_type[js_type];
if (R == null) {
return js_type.replace(/^\[object (.+)\]$/, '$1');
return (js_type.replace(/^\[object (.+)\]$/, '$1')).toLowerCase();
}

@@ -80,0 +83,0 @@ if (this.isa_function(R)) {

{
"name": "cnd",
"version": "1.0.9",
"version": "2.0.2",
"description": "a grab-bag NodeJS package mainly for functionalities that used to live in coffeenode-trm, coffeenode-bitsnpieces, and coffeenode-types",
"main": "lib/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./build && node lib/test.js"
},

@@ -27,9 +27,13 @@ "repository": {

"bloem": "^0.2.4",
"columnify": "^1.4.1",
"equals": "^1.0.0",
"es6-shim": "^0.32.2",
"columnify": "^1.5.4",
"equals": "^1.0.1",
"es6-shim": "^0.35.0",
"functional-red-black-tree": "^1.0.1",
"interval-skip-list": "^2.0.1",
"lodash": "^3.2.0",
"permute": "^1.0.0"
},
"devDependencies": {
"guy-test": "^1.1.2"
}
}

@@ -0,4 +1,18 @@

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- [cnd](#cnd)
- [CND Interval Tree](#cnd-interval-tree)
- [CND Shim](#cnd-shim)
- [CND TSort](#cnd-tsort)
- [TSort API](#tsort-api)
- [Some TDOP Links](#some-tdop-links)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
- [cnd](#cnd)
- [CND Interval Tree](#cnd-interval-tree)
- [CND Shim](#cnd-shim)

@@ -17,2 +31,32 @@ - [CND TSort](#cnd-tsort)

## CND Interval Tree
* https://www.youtube.com/watch?v=q0QOYtSsTg4
* https://www.youtube.com/watch?v=PHlTuCVxJz4
* https://github.com/mikolalysenko/functional-red-black-tree
* Simplified API (compared to `functional-red-black-tree`)
* possible to dynamically add nodes
* possible to access underlying red/black tree as `tree[ '%self' ]`, root node as `tree[ '%self' ][ 'root' ]`
* possible to access
```coffee
CND = require 'cnd'
ITREE = CND.INTERVALTREE
tree = ITREE.new_tree()
intervals = [
[ 3, 7, 'A', ]
[ 5, 7, 'B', ]
[ 8, 12, 'C', ]
[ 2, 14, 'D', ]
[ 4, 4, 'E', ]
]
ITREE.add_interval tree, interval for interval in intervals
for n in [ 0 .. 15 ]
console.log n
for node in ITREE.find tree, n
console.log node[ 'key' ], node[ 'value' ]
```
## CND Shim

@@ -19,0 +63,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc