tree_handler 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4f84c2af33d9bc188f1d79837dd4131b7d0505d78625c5729a63747eace2d94
4
- data.tar.gz: 89e71bc1056c0aa5c5904540dc1c405d80013f7f53b9a204bc09566da027f022
3
+ metadata.gz: 79d3c24fed8097d3bcfc15df3d0b7afd7d4dcfa965df02e445d438d4304b645c
4
+ data.tar.gz: df770293c7328d0be9fcee5f357e9900492848003e2fd957bbc5ec7377c3e09c
5
5
  SHA512:
6
- metadata.gz: 719a4923aad2588a5bf65102bf4643309248dc826177e4125e45fecd60855b062227819a43f221f10d443d44595de4e945a3817edaa205237908bec561c68cee
7
- data.tar.gz: 8d5c93d3e4d0721a1e2c58cc582e2629b027c9b14c3cbf004b99c3079aae0336fdac4de500aaac49de03b326daf62be015a13ca18249bcc7eee881d3be493350
6
+ metadata.gz: e53a26a4f054e86002aaaeffc86b63abe4d74d8fc2f69e4bf751f4a26892deb4092f7d9f3bf9bddbd776e6832bbf3bf23696e147a2e1a7822b21e1a4f309467e
7
+ data.tar.gz: 6aea9508d5bd129dd2b39bb5bfa6715409951ee07c8026c3780cdd063ad96d9294af98ca9069be435e466961ba1cf6f469792c0eb3e9da340715aca6400ecdd2
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # TreeHandler
2
+ TreeHandler is a ruby library allowing yourself to discover **binary trees**.
3
+ Build your own data structure and search trough your model with Tree Traversals (in-order, pre-order, post-order and level-order)
2
4
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tree_handler`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
6
  ## Installation
8
7
 
@@ -22,7 +21,88 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ Be aware that this library works only without duplicate value.
25
+
26
+ ### Modification methods
27
+
28
+ start by creating a new tree
29
+
30
+ ```ruby
31
+ my_object = TreeHandler.new(array)
32
+ # @params : an array of integer (duplicate value won't raise error, they are automatically removed)
33
+ # return : the full object with each node
34
+ ```
35
+
36
+
37
+ You can then modify by inserting or deleting some nodes by value
38
+
39
+ ```ruby
40
+ my_object.insert(value)
41
+ # @params : an integer (an existing value will raise an error)
42
+ # return : The created node or RuntimeError (The same value can't be inserted twice) if value exists already
43
+ ```
44
+ ```ruby
45
+ my_object.delete(value, parent_pointer = @root)
46
+ # @params1 : an integer
47
+ # @params2 : the node where the search will start. Default value : root of the tree
48
+ # return : The deleted node or nil of value not found
49
+ ```
50
+ To check if the tree is balanced (same depth on each child of the root), simply :
51
+
52
+ ```ruby
53
+ my_object.balanced?
54
+ # return : true if balanced
55
+ ```
56
+
57
+ To rebalance the tree, type :
58
+
59
+ ```ruby
60
+ my_object.rebalance!
61
+ # return : the full object with each node
62
+ ```
63
+ ### Navigation methods
64
+
65
+ [Tree traversal](https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_search_/_level_order) is a way to visit each node in your tree.
66
+
67
+ ```ruby
68
+ # preorder search
69
+ my_object.preorder
70
+ # return an array of integer
71
+
72
+ # inorder search
73
+ my_object.inorder
74
+ # return an array of integer
75
+
76
+ # postorder search
77
+ my_object.postorder
78
+ # return an array of integer
79
+
80
+ # breadth-first search / level order
81
+ my_object.level_order
82
+ # return an array of array for each level
83
+ ```
84
+
85
+ Other useful method
86
+
87
+ ```ruby
88
+ # find node for a certain value
89
+ my_object.find(integer, start_node = @root)
90
+ # @params1 : integer, the value of the node desired
91
+ # @params2 : the node where the search will start. Default value : root of the tree
92
+ # return the node or nil if not found
93
+
94
+ # find parent a certain value
95
+ my_object.find_parent(integer)
96
+ # @params1 : integer
97
+ # return the parent's node of the value searched or nil if not found
98
+ # know the depth of your tree
99
+ my_object.depth(start_node)
100
+ # @params1 : the node where the search will start.
101
+ # return an integer of the tree's height
102
+ ```
103
+
104
+
105
+
26
106
 
27
107
  ## Development
28
108
 
@@ -38,3 +118,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
38
118
  ## License
39
119
 
40
120
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
121
+
@@ -20,9 +20,13 @@ module TreeHandler
20
20
  end
21
21
 
22
22
  def insert(value)
23
- @data.push(value)
24
- node = Node.new(value)
25
- compare(root, node)
23
+ unless @data.include? value
24
+ @data.push(value)
25
+ node = Node.new(value)
26
+ compare(root, node)
27
+ else
28
+ raise "The same value can't be inserted twice"
29
+ end
26
30
  end
27
31
 
28
32
  def delete(value, parent_pointer = @root)
@@ -149,4 +153,4 @@ module TreeHandler
149
153
  result
150
154
  end
151
155
  end
152
- end
156
+ end
@@ -1,3 +1,3 @@
1
1
  module TreeHandler
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Hörler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-22 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Set of functions to create, modify and search in a binary tree from a
14
14
  list.
@@ -33,6 +33,7 @@ files:
33
33
  - lib/tree_handler/comparable.rb
34
34
  - lib/tree_handler/node.rb
35
35
  - lib/tree_handler/version.rb
36
+ - tree_handler-0.1.0.gem
36
37
  - tree_handler.gemspec
37
38
  homepage: https://github.com/Ichenn92/tree_handler
38
39
  licenses: