Skip to content

Commit

Permalink
resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzuber committed Sep 26, 2016
2 parents 431ac56 + f16b20f commit b7a2d82
Show file tree
Hide file tree
Showing 21 changed files with 391 additions and 108 deletions.
2 changes: 1 addition & 1 deletion bin/needle.min.js

Large diffs are not rendered by default.

210 changes: 210 additions & 0 deletions docs/doxide_output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
- **swap**(< _number_ >second, < _number_ >first) - *void* -

- **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* -

- **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* -

- **BinaryHeap**(< _function_ >[compare]) - *void* - Single argument constructor.

- **peek**(< _void_ >) - *any* - Returns the min node of the heap.

- **getParent**(< _number_ >index) - *any* - Returns the parent element of a given index in the heap.

- **getLeftChild**(< _number_ >index) - *any* - Returns the left child element of a given index in the heap.

- **getRightChild**(< _number_ >index) - *any* - Returns the right child element of a given index in the heap.

- **size**(< _void_ >) - *number* - Returns the size of the heap.

- **insert**(< _any_ >the) - *void* - Inserts a Node into the heap.

- **delete**(< _number_ >if) - *void* - Removes the min in the heap and reorders heap with new min.

- **_heapify**(< _number_ >the) - *void* - Actually does the heapify-ing.

- **heapify**(< _number_ >the) - *array* - Reorganizes the input array into a legal binary heap.

- **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* -

- **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* -

- **BinarySearchTree**(< _function_ >[compare]) - *void* - Single argument constructor.

- **hasRight**(< _Node_ >the) - *boolean* - Checks if the given node has a right branch.

- **hasLeft**(< _Node_ >the) - *boolean* - Checks if the given node has a left branch.

- **isLeaf**(< _Node_ >the) - *boolean* - Checks if the given node is a leaf.

- **emptySubtree**(< _Node_ >the) - *void* - Empties the subtree of the given node.

- **emptyTree**(< _void_ >) - *void* - Empties the entire tree.

- **heightSubtree**(< _Node_ >the) - *number* - Find the height of a subtree.

- **numNodesSubtree**(< _Node_ >the) - *number* - Find the number of nodes in a subtree.

- **numLeavesSubtree**(< _Node_ >the) - *number* - Find the number of leaves in a subtree.

- **insert**(< _Node_ >[node], < _any_ >the) - *void* - Insert a node into the tree.

- **search**(< _Node_ >[node], < _any_ >the) - *Node || false* - Search for a node in the tree.

- **shred**(< _any_ >input) - *number* - Transforms input into a number.

- **BitArray**(< _number_ >[size) - *void* - Instantiates a bit array with given size.

- **set**(< _boolean_ >the, < _number_ >the) - *void* - _no description provided_

- **get**(< _number_ >the) - *number* - Returns the bit from the bit array at desired location.

- **size**(< _void_ >) - *number* - Returns the size of the bit array.

- **resize**(< _number_ >the) - *void* - Adjusts the size of the bit array.

- **complement**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the complement bit array.

- **union**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the union bit array.

- **intersection**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the intersection bit array.

- **difference**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the difference bit array.

- **toString**(< _void_ >) - *string* - Converts the bit array into a string of bits.

- **DoublyLinkedList**(< _any_ >[data]) - *void* - Single argument constructor.

- **insertFront**(< _any_ >data) - *void* - Create a node from given data and insert to front of linked list.

- **insertNth**(< _any_ >data, < _number_ >position) - *void* - Create a node from given data and insert in given location of linked list.

- **insertAfter**(< _any_ >data, < _any_ >the) - *boolean* - Create a node from given data and inserts after a given node. of linked list.

- **insertBack**(< _any_ >data) - *void* - Create a node from given data and insert to end of linked list.

- **remove**(< _any_ >data) - *boolean* - Remove a node based on its given data

- **removeNth**(< _number_ >index) - *void* - Remove a node based on the given position in the linked list

- **find**(< _any_ >data) - *boolean || Node* - Find a node by a given value

- **hash**(< _any_ >the) - *number* -

- **removeCustom**(< _DoublyLinkedList_ >the, < _any_ >the) - *void* -

- **Hashmap**(< _void_ >) - *void* - No argument constructor.

- **put**(< _any_ >the, < _any_ >the) - *void* - Inserts an entry into the hashmap.

- **get**(< _any_ >the) - * || false* - Returns an entry based on a given key.

- **delete**(< _any_ >the) - *boolean* - Deletes an entry based on a given key.

- **next**(< _void_ >) - *key* - Updates the current node to the next node after returning the current node.

- **iterator**(< _void_ >) - *key* - Resets the internal iterator to the first entry and returns it.

- **size**(< _void_ >) - *number* - Returns the amount of unique entries within the hashmap.

- **KaryTree**(< _Node_ >the) - *void* - Creates an empty k-ary tree.

- **isLeaf**(< _Node_ >the) - *boolean* - Checks if the given node is a leaf.

- **emptySubtree**(< _Node_ >the) - *void* - Empties the subtree of the given node.

- **emptyTree**(< _void_ >) - *void* - Empties the entire tree.

- **search**(< _Node_ >[node], < _any_ >the) - *Node || false* - Search for a node in the tree.

- **Queue**(< _any_ >[data]) - *void* - Single argument constructor.

- **enqueue**(< _any_ >data) - *void* - Creates a node with the given data and adds that node to the back of the queue

- **dequeue**(< _void_ >) - *void* - Removes the node at the front of the queue

- **modInverse**(< _number_ >the, < _number_ >the) - *number* -

- **gcd**(< _number_ >second, < _number_ >first) - *number* -

- **safePOW**(< _number_ >the, < _number_ >the, < _number_ >the) - *number* -

- **ascii**(< _string_ >the) - *number* -

- **RollingHash**(< _number_ >the) - *void* - Single argument constructor which defines the base of the working

- **hash**(< _number || string || Array_ >the) - *number* - Computes a hash on the input assuming it is of the same base of the instance of the rolling hash.

- **append**(< _string || number_ >the) - *void* - Appends a new segment onto the rolling hash window.

- **skip**(< _string || number_ >the) - *void* - Disjoins the trailing segment of rolling hash window.

- **slide**(< _string || number_ >the, < _string || number_ >the) - *number* - Shifts the window over by one iteration and returns the new internal hash value.

- **set**(< _string || Array_ >either) - *number* - Sets the internal window of the rolling hash. Usually set with the beginning elements that fit within the window of the item to find.

- **SinglyLinkedList**(< _any_ >[data]) - *void* - Single argument constructor.

- **insertFront**(< _any_ >data) - *void* - Create a node from given data and insert to front of linked list.

- **insertNth**(< _any_ >data, < _number_ >position) - *void* - Create a node from given data and insert in given location of linked list.

- **insertAfter**(< _any_ >data, < _any_ >the) - *boolean* - Create a node from given data and inserts after a given node.

- **insertBack**(< _any_ >data) - *void* - Create a node from given data and insert to end of linked list.

- **remove**(< _any_ >data) - *boolean* - Remove a node based on its given data

- **removeNth**(< _number_ >index) - *void* - Remove a node based on the given position in the linked list

- **find**(< _any_ >data) - *boolean || Node* - Find a node by a given value

- **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* -

- **equal**(< _any_ >second, < _any_ >first) - *boolean* -

- **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* -

- **SortedArray**(< _function_ >[compare]) - *void* - Single argument constructor.

- **insert**(< _any_ >the) - *void* - Adds an element into the array in its sorted position.

- **delete**(< _any_ >the) - *boolean* - Deletes the first occurance of an element from the array.

- **get**(< _number_ >index) - *element* - Returns the element at the given index.

- **size**(< _void_ >) - *number* - Returns the amount of elements in the sorted array.

- **toString**(< _void_ >) - *string* -

- **Stack**(< _any_ >[data]) - *void* - Single argument constructor.

- **peek**(< _void_ >) - *Node* - Returns the top of the stack.

- **push**(< _any_ >data) - *void* - Creates a node with the given data and adds that node to the top of the stack

- **pop**(< _void_ >) - *Node* - Removes the node at the top of the stack.

### <a href="#multidirectional_tree_node" name="multidirectional_tree_node">Needle.Multidirectional_Tree_Node()</a>
**data** - *any* - Any data for the node to hold.<br />
**children** - *Array* - The set of Multidirectional_Tree_Node which are direct children to this node.<br />

- **Multidirectional_Tree_Node**(< _any_ >data) - *void* - Creates a multidirectional tree node.

- **appendChild**(< _any_ >data) - *void* - Appends data as a node as a direct child to the tree.

### <a href="#bidirectional_tree_node" name="bidirectional_tree_node">Needle.Bidirectional_Tree_Node()</a>
**data** - *any* - Any data for the node to hold.<br />
**right** - *Bidirectional_Tree_Node* - Points to the right child node.<br />
**left** - *Bidirectional_Tree_Node* - Points to the left child node.<br />

- **Bidirectional_Tree_Node**(< _any_ >data) - *void* - Constructs a bidirectional tree node.

### <a href="#bidirectional_node" name="bidirectional_node">Needle.Bidirectional_Node()</a>
**data** - *any* - Any data for the node to hold.<br />
**next** - *Bidirectional_node* - Points to the next node.<br />
**prev** - *Bidirectional_node* - Points to the previous node.<br />

- **Bidirectional_Node**(< _any_ >data) - *void* - Constructs a bidirectional node.

- **Unidirectional_Node**(< _any_ >data) - *void* - Constructs a unidirectional node.

6 changes: 6 additions & 0 deletions doxyfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"targets" : [
"./src"
],
"output" : "./docs/doxide_output.md"
}
2 changes: 1 addition & 1 deletion examples/scripts/needle.min.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions examples/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
<script type="text/javascript" src="needle.min.js"></script>
<script>

var heap = new Needle.BinaryHeap(function(a, b){
return (a > b);
});
var tree = new Needle.BinarySearchTree();

heap.heapify([1, 2, 3, 4, 7, 8, 9, 10, 14, 16]);

window.heap = heap;
tree.insert(2);
tree.insert(1);
tree.insert(4);
tree.insert(3);
tree.insert(5);

console.log(JSON.stringify(tree, null, 4));

tree.delete(4);

console.log(JSON.stringify(tree, null, 4));

window.tree = tree;

</script>
</body>
</html>
</html>
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var banner = ['/*!',

// Contacat & compress javascript files
gulp.task('dispatch', function(){
gulp.src(['src/*.js'])
.pipe(browserify({}))
gulp.src(['src/index.js'])
.pipe(browserify({
entries: ['./index.js']
}))
.pipe(uglify())
.pipe(rename({
basename: 'needle',
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
"main": "src/needle.js",
"scripts": {
"build": "gulp",
<<<<<<< Updated upstream
"dev": "gulp watch",
=======
"dev": "gulp && gulp watch || true",
"examples": "node ./examples/app.js || true",
>>>>>>> Stashed changes
"dev": "gulp && gulp watch || true",
"bench": "node --harmony benchmarks/runTests.js || true",
"unit": "node --harmony unit/runTests.js || true",
"lint": "./node_modules/.bin/eslint src/*.js || true",
Expand Down
63 changes: 59 additions & 4 deletions src/BinarySearchTree/binarySearchTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
* | search | O(n) |
* +------------------------------+
*
* TODO: let user set a custom `equal` function
*
*/

'use strict';
'use strict';

const Node = require('../Nodes/bidirectional_tree_node.js');

const Node = require('../__Nodes__/bidirectional_tree_node.js');
const Types = {
LEFT: 'left',
RIGHT: 'right'
}

// @TODO: let user set a custom `compare` function
/** @private @default
* Compares two elements and returns.
* @param {number} first index to compare
Expand Down Expand Up @@ -206,6 +210,57 @@ BinarySearchTree.prototype.insert = function(data, node){
}
}

/**
* Deletes a node from the tree with the value of `data`.
* @param {any} data The data of the node to delete.
* @return {boolean} Returns the success of the deletion success.
*/
BinarySearchTree.prototype.delete = function (data) {
deleteHelper = deleteHelper.bind(this);
return deleteHelper(data, this.root, null, null);
}

/**
* Deletes a node from the tree with the value of `data`.
* @param {any} data The data of the node to delete.
* @param {Node} node The current node being analyzed.
* @param {Node} nodeType The type of child of the current node being analyzed.
* @param {Node} parentNode The last node that was analyzed.
* @return {boolean} Returns the success of the deletion success.
*/
function deleteHelper (data, node, nodeType, parentNode) {
if (node === null) {
return false;
}

// @TODO handle object comparisons -- doing a stringify is horrible dont do that
if (data === node.data) {
if (nodeType === Types.RIGHT) {
parentNode.right = null;
} else {
parentNode.left = null;
}

// Fix tree
if (node.left) {
var nodeRightSubtree = node.right;
parentNode[nodeType] = node.left;
parentNode[nodeType].right = nodeRightSubtree;
} else if (node.right) {
var nodeLeftSubtree = node.left;
parentNode[nodeType] = node.right;
parentNode[nodeType].left = nodeLeftSubtree;
}
return true;
}

if (safeCompare(data, node.data, this.compare)) {
return deleteHelper(data, node.left, Types.LEFT, node);
} else {
return deleteHelper(data, node.right, Types.RIGHT, node);
}
}

/**
* Search for a node in the tree.
* @param {*} the data of the node being searched for
Expand Down
2 changes: 1 addition & 1 deletion src/DoublyLinkedList/doublyLinkedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

'use strict';

const Node = require('../__Nodes__/bidirectional_node.js');
const Node = require('../Nodes/bidirectional_node.js');

/**
* Single argument constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/KaryTree/karyTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

const Node = require('../__Nodes__/multidirectional_tree_node.js');
const Node = require('../Nodes/multidirectional_tree_node.js');

/**
* Creates an empty k-ary tree.
Expand Down
21 changes: 21 additions & 0 deletions src/Nodes/bidirectional_node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @header
* Bidirectional_Node
* @property {any} data Any data for the node to hold
* @property {Bidirectional_node} next Points to the next node
* @property {Bidirectional_node} prev Points to the previous node
*/

'use strict';

/** @constructor
* Constructs a bidirectional node.
* @param {*} data Any data for the node to hold
* @return {void}
*/
const Bidirectional_Node = function(data){
this.data = data || undefined;
this.next = null;
this.prev = null;
};

module.exports = Bidirectional_Node;
Loading

0 comments on commit b7a2d82

Please sign in to comment.