keso 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ jeweler
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -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) || key_or_hash.is_a?(Hash)
9
- key_or_hash.keys.each do |key|
10
- @hash[key] = key_or_hash[key]
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.clone
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.clone
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.clone
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
 
@@ -5,9 +5,22 @@ class Tuple
5
5
  @hash = nil
6
6
 
7
7
  def initialize *args
8
- hash = ImmutableHash.new *args
9
- @hash = ImmutableHash.new
10
- @heading = Heading.new
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
- @heading = @heading.add(name_or_attribute)
21
- @hash = @hash.add(name_or_attribute,value)
33
+ heading << name_or_attribute
22
34
  else
23
35
  if value.is_a? Relation
24
- @heading = @heading.add(Attribute.new(name_or_attribute,value.heading))
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
- @heading = @heading.add(Attribute.new(name_or_attribute,value.class))
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
- @tab_count = 0
4
+ @@tab_count = 0
5
5
 
6
6
  def puts object
7
- super "\t"*@tab_count + object.to_s
7
+ super ("\t"*@@tab_count) + object.to_s
8
8
  end
9
9
 
10
10
  def timeit name, &block
11
11
 
12
- @tab_count += 1
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
- @tab_count -= 1
20
+ @@tab_count -= 1
21
21
  end
22
22
 
23
23
  load 'timeit/relation_bench.rb'
@@ -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: false
5
- segments:
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-03-20 00:00:00 +01:00
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: -3964452428481869928
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.3.7
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