ds 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.rdoc +490 -0
- data/Rakefile +1 -1
- data/lib/ds.rb +17 -19
- data/lib/ds/ext/array_x.rb +35 -0
- data/lib/ds/graphs/graph.rb +36 -32
- data/lib/ds/graphs/graph_as_matrix.rb +22 -23
- data/lib/ds/graphs/graph_as_tri_matrix.rb +1 -2
- data/lib/ds/lists/list.rb +18 -21
- data/lib/ds/matrixes/array_2d.rb +4 -0
- data/lib/ds/pair.rb +14 -0
- data/lib/ds/queues/priority_queue.rb +36 -0
- data/lib/ds/queues/queue.rb +1 -1
- data/lib/ds/sets/ordered_set.rb +32 -0
- data/lib/ds/trees/binary_heap.rb +45 -14
- data/lib/ds/trees/binary_search_tree.rb +3 -1
- data/lib/ds/trees/binary_tree.rb +11 -5
- data/lib/ds/trees/complete_binary_tree.rb +24 -16
- data/lib/ds/trees/tree.rb +3 -3
- data/lib/ds/trees/tree_walker.rb +7 -6
- data/lib/ds/trees/trie.rb +14 -20
- data/lib/ds/version.rb +1 -1
- data/test/help.rb +12 -3
- data/test/test_array2d.rb +14 -4
- data/test/test_array_x.rb +27 -7
- data/test/test_binary_heap.rb +19 -1
- data/test/test_binary_search_tree.rb +8 -1
- data/test/test_binary_tree.rb +7 -1
- data/test/test_complete_binary_tree.rb +34 -6
- data/test/test_digraph.rb +1 -1
- data/test/test_graph.rb +10 -1
- data/test/test_list.rb +59 -2
- data/test/test_ordered_set.rb +28 -0
- data/test/test_pair.rb +26 -0
- data/test/test_priority_queue.rb +134 -0
- data/test/test_queue.rb +3 -3
- data/test/test_stack.rb +0 -2
- data/test/test_tree.rb +32 -9
- data/test/test_tree_walker.rb +22 -0
- data/test/test_trie.rb +20 -2
- metadata +13 -81
- data/doc/Array.html +0 -264
- data/doc/DS.html +0 -292
- data/doc/DS/Array2D.html +0 -345
- data/doc/DS/BinaryHeap.html +0 -493
- data/doc/DS/BinarySearchTree.html +0 -313
- data/doc/DS/BinaryTree.html +0 -433
- data/doc/DS/CompleteBinaryTree.html +0 -550
- data/doc/DS/CyclicList.html +0 -234
- data/doc/DS/Digraph.html +0 -299
- data/doc/DS/Edge.html +0 -283
- data/doc/DS/ExpandableArray.html +0 -316
- data/doc/DS/Graph.html +0 -739
- data/doc/DS/GraphAsList.html +0 -361
- data/doc/DS/GraphAsMatrix.html +0 -633
- data/doc/DS/GraphAsTriMatrix.html +0 -274
- data/doc/DS/List.html +0 -1263
- data/doc/DS/ListElement.html +0 -344
- data/doc/DS/Queue.html +0 -517
- data/doc/DS/Ring.html +0 -323
- data/doc/DS/Stack.html +0 -407
- data/doc/DS/Tree.html +0 -770
- data/doc/DS/TreeWalker.html +0 -561
- data/doc/DS/TriMatrix.html +0 -338
- data/doc/created.rid +0 -25
- data/doc/ds/graphs/digraph_rb.html +0 -52
- data/doc/ds/graphs/edge_rb.html +0 -52
- data/doc/ds/graphs/graph_as_list_rb.html +0 -52
- data/doc/ds/graphs/graph_as_matrix_rb.html +0 -52
- data/doc/ds/graphs/graph_as_tri_matrix_rb.html +0 -52
- data/doc/ds/graphs/graph_rb.html +0 -52
- data/doc/ds/lists/cyclic_list_rb.html +0 -52
- data/doc/ds/lists/list_element_rb.html +0 -52
- data/doc/ds/lists/list_rb.html +0 -52
- data/doc/ds/lists/ring_rb.html +0 -52
- data/doc/ds/matrixes/array_2d_rb.html +0 -52
- data/doc/ds/matrixes/expandable_array_rb.html +0 -52
- data/doc/ds/matrixes/tri_matrix_rb.html +0 -52
- data/doc/ds/queues/queue_rb.html +0 -52
- data/doc/ds/stacks/stack_rb.html +0 -52
- data/doc/ds/trees/binary_heap_rb.html +0 -52
- data/doc/ds/trees/binary_search_tree_rb.html +0 -52
- data/doc/ds/trees/binary_tree_rb.html +0 -52
- data/doc/ds/trees/complete_binary_tree_rb.html +0 -52
- data/doc/ds/trees/tree_rb.html +0 -52
- data/doc/ds/trees/tree_walker_rb.html +0 -52
- data/doc/ds/version_rb.html +0 -52
- data/doc/ds_rb.html +0 -98
- data/doc/ext/ext_rb.html +0 -52
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -375
- data/doc/js/darkfish.js +0 -116
- data/doc/js/jquery.js +0 -32
- data/doc/js/quicksearch.js +0 -114
- data/doc/js/thickbox-compressed.js +0 -10
- data/doc/rdoc.css +0 -763
- data/lib/ds/ext/ext.rb +0 -36
- data/lib/ds/graphs/graph_as_list.rb +0 -48
data/lib/ds/ext/ext.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module DS
|
2
|
-
module ArrayX
|
3
|
-
|
4
|
-
#Checks if array is already sorted.
|
5
|
-
def sorted?(order=:any)
|
6
|
-
return true if size < 2
|
7
|
-
|
8
|
-
case order
|
9
|
-
when :asc
|
10
|
-
(size-2).times{ |i| return false if self[i] > self[i+1] }
|
11
|
-
when :desc
|
12
|
-
(size-2).times{ |i| return false if self[i] < self[i+1] }
|
13
|
-
else
|
14
|
-
return (self[0] < self[1])? sorted?(:asc) : sorted?(:desc)
|
15
|
-
end
|
16
|
-
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
#Pushes element e only if it is not already in the array. Returns index of
|
21
|
-
#elemnt e.
|
22
|
-
def push_uniq e
|
23
|
-
if include? e
|
24
|
-
index e
|
25
|
-
else
|
26
|
-
push e
|
27
|
-
size-1
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
#Tail
|
32
|
-
def tail
|
33
|
-
self[1..-1]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module DS
|
2
|
-
class GraphAsList
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@store = {} # the graph // {node => { edge1 => weight, edge2 => weight}, node2 => ...
|
6
|
-
@nodes = Array.new
|
7
|
-
@INFINITY = 1 << 64
|
8
|
-
end
|
9
|
-
|
10
|
-
def add_edge(x,y,w=nil) # s= source, t= target, w= weight
|
11
|
-
if (not @store.has_key?(x))
|
12
|
-
@store[x] = {y=>w}
|
13
|
-
else
|
14
|
-
@store[x][y] = w
|
15
|
-
end
|
16
|
-
|
17
|
-
# Begin code for non directed graph (inserts the other edge too)
|
18
|
-
|
19
|
-
if (not @store.has_key?(y))
|
20
|
-
@store[y] = {x=>w}
|
21
|
-
else
|
22
|
-
@store[y][x] = w
|
23
|
-
end
|
24
|
-
|
25
|
-
# End code for non directed graph (ie. deleteme if you want it directed)
|
26
|
-
|
27
|
-
if (not @nodes.include?(x))
|
28
|
-
@nodes << x
|
29
|
-
end
|
30
|
-
if (not @nodes.include?(y))
|
31
|
-
@nodes << y
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_edges(edges)
|
36
|
-
for e in edges
|
37
|
-
add(e.from,e.to)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def each_vertex
|
42
|
-
@adj_matrix.keys.each do |vertex|
|
43
|
-
yield vertex
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|