Skip to content

Commit 3e0fcb9

Browse files
author
dafeng.xdf
committed
First Commit
0 parents  commit 3e0fcb9

16 files changed

+585
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
node_modules
3+
npm-debug.log
4+
*.swp
5+
*.swo
6+
.sw*
7+
.idea/*
8+
Thumbs.db

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage.html
2+
lib-cov/
3+
node_modules

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "0.8"
4+
- "0.10"

HISTORY

Whitespace-only changes.

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 xdf
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
TESTS = test/*.test.js
2+
TIMEOUT = 1000
3+
MOCHA_OPTS =
4+
5+
install:
6+
@npm install --registry=http://r.cnpmjs.org --disturl=http://dist.cnpmjs.org
7+
8+
jshint: install
9+
@./node_modules/.bin/jshint .
10+
11+
test: install
12+
@NODE_ENV=test ./node_modules/.bin/mocha \
13+
--harmony \
14+
--reporter $(REPORTER) \
15+
--timeout $(TIMEOUT) \
16+
$(MOCHA_OPTS) \
17+
$(TESTS)
18+
19+
test-cov cov: install
20+
@NODE_ENV=test node --harmony \
21+
node_modules/.bin/istanbul cover --preserve-comments \
22+
./node_modules/.bin/_mocha \
23+
-- -u exports \
24+
--reporter $(REPORTER) \
25+
--timeout $(TIMEOUT) \
26+
$(MOCHA_OPTS) \
27+
$(TESTS)
28+
@./node_modules/.bin/cov coverage

README.md

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Class BinaryHeap
2+
3+
* Version: package.version
4+
* Author: xdf
5+
6+
[doc2](https://commons.apache.org/proper/commons-collections/javadocs/api-2.1.1/org/apache/commons/collections/BinaryHeap.html)
7+
8+
## Constructor Detail
9+
10+
### BinaryHeap()
11+
12+
Constructs a new minimum binary heap.
13+
14+
15+
### BinaryHeap(Array comparator)
16+
17+
Constructs a new BinaryHeap that will use the given comparator to order its elements.
18+
19+
### BinaryHeap(Number capacity)
20+
21+
Constructs a new minimum binary heap with the specified initial capacity.
22+
23+
` Parameters: `
24+
25+
* capacity - The initial capacity for the heap. This value must be greater than zero.
26+
27+
` Throws: `
28+
29+
* IllegalArgumentException - if capacity is <= 0
30+
31+
### BinaryHeap(Number capacity, Array comparator)
32+
33+
Constructs a new BinaryHeap.
34+
35+
` Parameters: `
36+
37+
* capacity - the initial capacity for the heap
38+
* comparator - the comparator used to order the elements, null means use natural order
39+
40+
` Throws: `
41+
42+
* IllegalArgumentException - if capacity is <= 0
43+
44+
45+
## Method Detail
46+
47+
### void clear()
48+
49+
Clears all elements from queue.
50+
51+
### boolean isEmpty()
52+
53+
Tests if queue is empty.
54+
55+
` Returns: `
56+
57+
* true if queue is empty; false otherwise.
58+
59+
### boolean isFull()
60+
61+
Tests if queue is full.
62+
63+
` Returns: `
64+
65+
* true if queue is full; false otherwise.
66+
67+
### void insert(Object element)
68+
69+
Inserts an element into queue.
70+
71+
` Parameters: `
72+
73+
* element - the element to be inserted
74+
75+
### object peek()
76+
77+
Returns the element on top of heap but don't remove it.
78+
79+
` Returns: `
80+
81+
* the element at top of heap
82+
83+
` Throws: `
84+
85+
* NoSuchElementException - if isEmpty() == true
86+
87+
### object pop()
88+
89+
Returns the element on top of heap and remove it.
90+
91+
` Returns: `
92+
93+
* the element at top of heap
94+
95+
` Throws: `
96+
97+
* NoSuchElementException - if isEmpty() == true
98+
99+
100+
### string toString()
101+
102+
Returns a string representation of this heap.
103+
104+
` Returns: `
105+
106+
* a string representation of this heap
107+
108+
### object iterator()
109+
110+
Returns an iterator over this heap's elements.
111+
112+
` Returns: `
113+
114+
* an iterator over this heap's elements
115+
116+
### boolean add(Object object)
117+
118+
Adds an object to this heap. Same as insert(Object).
119+
120+
` Parameters: `
121+
122+
* object - the object to add
123+
124+
` Returns: `
125+
126+
* true, always
127+
128+
### object get()
129+
130+
Returns the priority element. Same as peek().
131+
132+
` Returns: `
133+
134+
* the priority element
135+
136+
` Throws: `
137+
138+
* BufferUnderflowException - if this heap is empty
139+
140+
### object remove
141+
142+
Removes the priority element. Same as pop().
143+
144+
` Returns: `
145+
146+
* the removed priority element
147+
148+
` Throws: `
149+
150+
* BufferUnderflowException - if this heap is empty
151+
152+
### number size
153+
154+
Returns the number of elements in this heap.
155+
156+
` Returns: `
157+
158+
* the number of elements in this heap
159+
160+
## License
161+
162+
The MIT License (MIT)
163+
164+
Copyright (c) 2013 xdf
165+
166+
Permission is hereby granted, free of charge, to any person obtaining a copy of
167+
this software and associated documentation files (the "Software"), to deal in
168+
the Software without restriction, including without limitation the rights to
169+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
170+
the Software, and to permit persons to whom the Software is furnished to do so,
171+
subject to the following conditions:
172+
173+
The above copyright notice and this permission notice shall be included in all
174+
copies or substantial portions of the Software.
175+
176+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
178+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
179+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
180+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
181+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bin/BinaryHeap

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
/* ================================================================
3+
* BinaryHeap by xdf(xudafeng[at]126.com)
4+
*
5+
* first created at : Wed Aug 20 2014 10:35:14 GMT+0800 (CST)
6+
*
7+
* ================================================================
8+
* Copyright 2013 xdf
9+
*
10+
* Licensed under the MIT License
11+
* You may not use this file except in compliance with the License.
12+
*
13+
* ================================================================ */
14+
15+
'use strict';

index.html

Whitespace-only changes.

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./lib/BinaryHeap');

0 commit comments

Comments
 (0)