bhash 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bhash.rb +29 -15
- data/lib/bhash/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa0d4b5e3b8b48ee4c23fd80cbe6e91ecc452c46b5f37ef7855023765204b981
|
4
|
+
data.tar.gz: d72a4d2eefdb981116bf9c6e566c200d7f7857182dc973d312aa93f16d15e266
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82bb102973650f71e56938289efea4a9486cead0906f1f0173bbff0e274517bd6897c74f34c8c52754706139f0cf3cd22c13fdf474031a2f8d6843357bbf448
|
7
|
+
data.tar.gz: 34d6854acefd95a1c8d2340aa5476cc0f858a5cf0791445a3e05405e9d6ff132c21abf1843bc89bb2586595c06effc79d815a02b17bd6515b250aae1bf528d64
|
data/lib/bhash.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
require "bhash/version"
|
2
2
|
|
3
3
|
|
4
|
+
|
4
5
|
class BHash
|
5
6
|
|
6
|
-
def initialize()
|
7
|
+
def initialize(hmap = nil)
|
7
8
|
@hash = Hash.new()
|
8
9
|
@rhash = Hash.new()
|
10
|
+
if hmap
|
11
|
+
hmap.each do |r,s|
|
12
|
+
add(r,s)
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
17
|
+
|
11
18
|
def find(h)
|
12
19
|
if @hash.has_key?(h)
|
13
20
|
return @hash[h]
|
@@ -17,19 +24,27 @@ class BHash
|
|
17
24
|
return nil
|
18
25
|
end
|
19
26
|
|
20
|
-
def add(r,s)
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def add(r, s = nil)
|
28
|
+
if s
|
29
|
+
if not present?(r)
|
30
|
+
else
|
31
|
+
raise "Error! #{r} already Present"
|
32
|
+
return
|
33
|
+
end
|
34
|
+
if not present?(s)
|
35
|
+
else
|
36
|
+
raise "Error! #{s} already Present"
|
37
|
+
return
|
38
|
+
end
|
39
|
+
@hash[r] = s
|
40
|
+
@rhash[s] = r
|
41
|
+
elsif r.is_a?(Hash)
|
42
|
+
r.each do |r,s|
|
43
|
+
add(r,s)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
raise "Error! Invalid Type"
|
30
47
|
end
|
31
|
-
@hash[r] = s
|
32
|
-
@rhash[s] = r
|
33
48
|
end
|
34
49
|
|
35
50
|
def delete(h)
|
@@ -47,7 +62,7 @@ class BHash
|
|
47
62
|
end
|
48
63
|
|
49
64
|
def print()
|
50
|
-
|
65
|
+
puts @hash.to_s
|
51
66
|
end
|
52
67
|
|
53
68
|
def present?(h)
|
@@ -96,4 +111,3 @@ class BHash
|
|
96
111
|
end
|
97
112
|
end
|
98
113
|
|
99
|
-
|
data/lib/bhash/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tejas Chendekar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Creates Bidirectional hash with key-to-key pair.
|
14
14
|
email:
|