keso 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +15 -0
- data/VERSION +1 -1
- data/lib/values/heading.rb +7 -0
- data/lib/values/immutable_hash.rb +15 -9
- data/lib/values/tuple.rb +26 -9
- data/timeit.rb +4 -4
- data/timeit/relation_bench.rb +40 -0
- metadata +6 -17
data/Gemfile.lock
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/values/heading.rb
CHANGED
@@ -8,6 +8,8 @@ class Heading
|
|
8
8
|
@attributes = @attributes.add values
|
9
9
|
elsif values.is_a? ImmutableSet
|
10
10
|
@attributes = values
|
11
|
+
elsif values.is_a? Array
|
12
|
+
@attributes = ImmutableSet.new values
|
11
13
|
elsif values.is_a? Hash
|
12
14
|
@attributes = @attributes.add(Attribute.new(values))
|
13
15
|
elsif values.is_a? Heading
|
@@ -19,6 +21,11 @@ class Heading
|
|
19
21
|
else
|
20
22
|
raise 'Invalid parameter, expected a hash with name and type or a attribute'
|
21
23
|
end
|
24
|
+
|
25
|
+
# Validate
|
26
|
+
@attributes.each do |a|
|
27
|
+
raise "Invalid input, all values must be an attribute or hash that creats an attribute" unless a.is_a? Attribute
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
31
|
def names
|
@@ -5,13 +5,19 @@ class ImmutableHash
|
|
5
5
|
|
6
6
|
@hash = {}
|
7
7
|
|
8
|
-
if key_or_hash.is_a?(ImmutableHash)
|
9
|
-
key_or_hash.
|
10
|
-
|
8
|
+
if key_or_hash.is_a?(ImmutableHash)
|
9
|
+
@hash = key_or_hash.inner_hash
|
10
|
+
elsif key_or_hash.is_a?(Hash)
|
11
|
+
if(key_or_hash.frozen?)
|
12
|
+
@hash = key_or_hash
|
13
|
+
else
|
14
|
+
@hash = key_or_hash.dup
|
11
15
|
end
|
12
16
|
elsif !key_or_hash.nil?
|
13
17
|
@hash[key_or_hash] = value
|
14
18
|
end
|
19
|
+
|
20
|
+
@hash.freeze
|
15
21
|
end
|
16
22
|
|
17
23
|
def [] key
|
@@ -50,7 +56,7 @@ class ImmutableHash
|
|
50
56
|
|
51
57
|
def delete *to_remove
|
52
58
|
|
53
|
-
newHash = @hash.
|
59
|
+
newHash = @hash.dup
|
54
60
|
|
55
61
|
to_remove.each do |to_remove|
|
56
62
|
if to_remove.is_a?(ImmutableHash) || to_remove.is_a?(Hash)
|
@@ -66,20 +72,20 @@ class ImmutableHash
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
|
-
ImmutableHash.new newHash
|
75
|
+
ImmutableHash.new newHash.freeze
|
70
76
|
end
|
71
77
|
|
72
78
|
def add key_or_hash,value = nil
|
73
79
|
if key_or_hash.is_a?(ImmutableHash) || key_or_hash.is_a?(Hash)
|
74
|
-
newHash = @hash.
|
80
|
+
newHash = @hash.dup
|
75
81
|
key_or_hash.keys.each do |key|
|
76
82
|
newHash[key] = key_or_hash[key]
|
77
83
|
end
|
78
|
-
ImmutableHash.new(newHash)
|
84
|
+
ImmutableHash.new(newHash.freeze)
|
79
85
|
else
|
80
|
-
newHash = @hash.
|
86
|
+
newHash = @hash.dup
|
81
87
|
newHash[key_or_hash] = value
|
82
|
-
ImmutableHash.new newHash
|
88
|
+
ImmutableHash.new newHash.freeze
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
data/lib/values/tuple.rb
CHANGED
@@ -5,9 +5,22 @@ class Tuple
|
|
5
5
|
@hash = nil
|
6
6
|
|
7
7
|
def initialize *args
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
# Fix so that we have the input as a hash
|
10
|
+
hash = args.first
|
11
|
+
unless(hash.is_a?(Hash) || hash.is_a?(ImmutableHash))
|
12
|
+
hash = {args[0] => args[1]}
|
13
|
+
end
|
14
|
+
|
15
|
+
if args.length == 0
|
16
|
+
hash = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Validate and put the input as we want it
|
21
|
+
values = {}
|
22
|
+
heading = []
|
23
|
+
|
11
24
|
hash.each do |name_or_attribute,value|
|
12
25
|
if name_or_attribute.is_a? Attribute
|
13
26
|
|
@@ -17,18 +30,22 @@ class Tuple
|
|
17
30
|
throw "#{value} is not the same as #{name_or_attribute.type}" if value.class != name_or_attribute.type
|
18
31
|
end
|
19
32
|
|
20
|
-
|
21
|
-
@hash = @hash.add(name_or_attribute,value)
|
33
|
+
heading << name_or_attribute
|
22
34
|
else
|
23
35
|
if value.is_a? Relation
|
24
|
-
|
25
|
-
@hash = @hash.add(Attribute.new(name_or_attribute,value.heading),value)
|
36
|
+
heading << Attribute.new(name_or_attribute,value.heading)
|
26
37
|
else
|
27
|
-
|
28
|
-
@hash = @hash.add(Attribute.new(name_or_attribute,value.class),value)
|
38
|
+
heading << Attribute.new(name_or_attribute,value.class)
|
29
39
|
end
|
30
40
|
end
|
41
|
+
|
42
|
+
values[heading.last] = value
|
31
43
|
end
|
44
|
+
|
45
|
+
# set it
|
46
|
+
@hash = ImmutableHash.new values
|
47
|
+
@heading = Heading.new heading
|
48
|
+
|
32
49
|
end
|
33
50
|
|
34
51
|
def count
|
data/timeit.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
old_puts = puts
|
4
|
-
|
4
|
+
@@tab_count = 0
|
5
5
|
|
6
6
|
def puts object
|
7
|
-
super "\t"
|
7
|
+
super ("\t"*@@tab_count) + object.to_s
|
8
8
|
end
|
9
9
|
|
10
10
|
def timeit name, &block
|
11
11
|
|
12
|
-
|
12
|
+
@@tab_count += 1
|
13
13
|
start_time = Time.now
|
14
14
|
puts ""
|
15
15
|
puts "(#{name}) runing"
|
@@ -17,7 +17,7 @@ def timeit name, &block
|
|
17
17
|
puts "(#{name}) total time: #{Time.now - start_time}"
|
18
18
|
puts ""
|
19
19
|
|
20
|
-
|
20
|
+
@@tab_count -= 1
|
21
21
|
end
|
22
22
|
|
23
23
|
load 'timeit/relation_bench.rb'
|
data/timeit/relation_bench.rb
CHANGED
@@ -20,9 +20,49 @@ timeit "Tuple" do
|
|
20
20
|
r << Tuple.new({:name => 'Emma',:age => i})
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
timeit "Add 2000 values to a tuple" do
|
25
|
+
r = []
|
26
|
+
t = Tuple.new
|
27
|
+
|
28
|
+
2000.times do |i|
|
29
|
+
r << t
|
30
|
+
t = t.add({"name_#{i}".to_sym => i})
|
31
|
+
end
|
32
|
+
end
|
23
33
|
|
24
34
|
end
|
25
35
|
|
36
|
+
timeit "ImmutableHash" do
|
37
|
+
|
38
|
+
timeit "Add 1000 values" do
|
39
|
+
|
40
|
+
ihash = ImmutableHash.new
|
41
|
+
|
42
|
+
1000.times do |i|
|
43
|
+
ihash = ihash.add({"bal#{i}" => i})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
timeit "Add 2000 values" do
|
48
|
+
|
49
|
+
ihash = ImmutableHash.new
|
50
|
+
|
51
|
+
2000.times do |i|
|
52
|
+
ihash = ihash.add({"bal#{i}" => i})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
timeit "Add 10000 values" do
|
57
|
+
|
58
|
+
ihash = ImmutableHash.new
|
59
|
+
|
60
|
+
10000.times do |i|
|
61
|
+
ihash = ihash.add({"bal#{i}" => i})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
26
66
|
|
27
67
|
timeit "ImmutableSet" do
|
28
68
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Darwin
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-04-22 00:00:00 +02:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,8 +20,6 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
23
|
version: "0"
|
30
24
|
type: :runtime
|
31
25
|
prerelease: false
|
@@ -37,10 +31,6 @@ dependencies:
|
|
37
31
|
requirements:
|
38
32
|
- - ">="
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 1
|
42
|
-
- 2
|
43
|
-
- 9
|
44
34
|
version: 1.2.9
|
45
35
|
type: :development
|
46
36
|
prerelease: false
|
@@ -59,6 +49,7 @@ files:
|
|
59
49
|
- .document
|
60
50
|
- .rspec
|
61
51
|
- Gemfile
|
52
|
+
- Gemfile.lock
|
62
53
|
- LICENSE
|
63
54
|
- README.rdoc
|
64
55
|
- Rakefile
|
@@ -95,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
86
|
requirements:
|
96
87
|
- - ">="
|
97
88
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
89
|
+
hash: 2938014607106573032
|
99
90
|
segments:
|
100
91
|
- 0
|
101
92
|
version: "0"
|
@@ -104,13 +95,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
95
|
requirements:
|
105
96
|
- - ">="
|
106
97
|
- !ruby/object:Gem::Version
|
107
|
-
segments:
|
108
|
-
- 0
|
109
98
|
version: "0"
|
110
99
|
requirements: []
|
111
100
|
|
112
101
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.
|
102
|
+
rubygems_version: 1.6.2
|
114
103
|
signing_key:
|
115
104
|
specification_version: 3
|
116
105
|
summary: Cottage cheees with lots of relational theory
|