ninjudd-tuple 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +32 -0
- data/VERSION.yml +4 -0
- data/test/test_helper.rb +10 -0
- data/test/tuple_test.rb +61 -0
- metadata +58 -0
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Tuple
|
2
|
+
|
3
|
+
Tuple provides fast, binary-sortable serialization for arrays of simple Ruby types. This
|
4
|
+
means you do not have to deserialize your tuples to store them. This leads to significant
|
5
|
+
performance benifits when using Tuples as keys for a BTree.
|
6
|
+
|
7
|
+
A Tuple is just an Array of any number of simple Ruby types. The following types are
|
8
|
+
supported (listed in ascending sort order):
|
9
|
+
|
10
|
+
1. NilClass
|
11
|
+
2. FalseClass
|
12
|
+
3. Integer (Fixnum or Bignum)
|
13
|
+
4. String
|
14
|
+
5. Symbol
|
15
|
+
6. True
|
16
|
+
|
17
|
+
== Usage:
|
18
|
+
|
19
|
+
require 'tuple'
|
20
|
+
|
21
|
+
data = Tuple.dump([1, -43, :foo, "bar", true, false, nil])
|
22
|
+
=> "\000\000\020\000\000\000\000\001..."
|
23
|
+
Tuple.load(data)
|
24
|
+
=> [1, -43, :foo, "bar", true, false, nil]
|
25
|
+
|
26
|
+
== Install:
|
27
|
+
|
28
|
+
sudo gem install ninjudd-tuple -s http://gems.github.com
|
29
|
+
|
30
|
+
== License:
|
31
|
+
|
32
|
+
Copyright (c) 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE
|
data/VERSION.yml
ADDED
data/test/test_helper.rb
ADDED
data/test/tuple_test.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TupleTest < Test::Unit::TestCase
|
4
|
+
should "dump and load arrays of simple types" do
|
5
|
+
t = [1, true, :foo, "foo", -1001, false, nil]
|
6
|
+
assert_equal t, Tuple.load(Tuple.dump(t))
|
7
|
+
end
|
8
|
+
|
9
|
+
should "dump and load fixnums and bignums" do
|
10
|
+
t = [2**64, 2**32, 2**32 - 1, 2**31, 2**31 - 1, 1, 0]
|
11
|
+
t = t + t.collect {|n| -n}
|
12
|
+
assert_equal t, Tuple.load(Tuple.dump(t))
|
13
|
+
end
|
14
|
+
|
15
|
+
should "sort tuples using binary" do
|
16
|
+
tuples = [
|
17
|
+
[1, "foo"],
|
18
|
+
[1, true],
|
19
|
+
[2],
|
20
|
+
[1],
|
21
|
+
[nil],
|
22
|
+
[true],
|
23
|
+
[:foo, -1],
|
24
|
+
[:foo, -2**64],
|
25
|
+
[:foo, 2**64],
|
26
|
+
[1, "foo", 7, nil, false, true],
|
27
|
+
[1, "foo", 7, nil, false, false],
|
28
|
+
["charles", "atlas"],
|
29
|
+
["charles", "atlas", "shrugged"],
|
30
|
+
["charles", "atlantic"],
|
31
|
+
["charles", "atlas jr."],
|
32
|
+
["charles", "atlas", "world's", "strongest", "man"],
|
33
|
+
["charles", "atlas", 5],
|
34
|
+
]
|
35
|
+
|
36
|
+
expected = [
|
37
|
+
[nil],
|
38
|
+
[1],
|
39
|
+
[1, "foo"],
|
40
|
+
[1, "foo", 7, nil, false, false],
|
41
|
+
[1, "foo", 7, nil, false, true],
|
42
|
+
[1, true],
|
43
|
+
[2],
|
44
|
+
["charles", "atlantic"],
|
45
|
+
["charles", "atlas"],
|
46
|
+
["charles", "atlas", 5],
|
47
|
+
["charles", "atlas", "shrugged"],
|
48
|
+
["charles", "atlas", "world's", "strongest", "man"],
|
49
|
+
["charles", "atlas jr."],
|
50
|
+
[:foo, -18446744073709551616],
|
51
|
+
[:foo, -1],
|
52
|
+
[:foo, 18446744073709551616],
|
53
|
+
[true]
|
54
|
+
]
|
55
|
+
assert_equal expected, tuples.sort_by {|t| Tuple.dump(t)}
|
56
|
+
|
57
|
+
100.times do
|
58
|
+
assert_equal expected, tuples.shuffle.sort_by {|t| Tuple.dump(t)}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ninjudd-tuple
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Balthrop
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Fast, binary-sortable serialization for arrays of simple Ruby types.
|
17
|
+
email: code@justinbalthrop.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- VERSION.yml
|
27
|
+
- test/test_helper.rb
|
28
|
+
- test/tuple_test.rb
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/ninjudd/tuple
|
31
|
+
licenses:
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --inline-source
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.3.5
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: TODO
|
57
|
+
test_files: []
|
58
|
+
|