idgen32 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +12 -0
- data/Gemfile +3 -0
- data/Manifest +15 -0
- data/README.md +54 -0
- data/Rakefile +29 -0
- data/ext/rlibidgen32/extconf.rb +23 -0
- data/ext/rlibidgen32/idgen.c +157 -0
- data/ext/rlibidgen32/idgen.h +33 -0
- data/ext/rlibidgen32/rlibidgen32.i +11 -0
- data/idgen32.gemspec +28 -0
- data/init.rb +1 -0
- data/lib/idgen32.rb +16 -0
- data/lib/idgen32/version.rb +3 -0
- data/test/bench.rb +28 -0
- data/test/binding_test.rb +9 -0
- data/test/idgen32_test.rb +9 -0
- data/test/test_helper.rb +2 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a128d8041ae090d56ba20dcd4983b0ea8185268
|
4
|
+
data.tar.gz: d3bc3efefdadf48d337af78d8e137e4e752e6421
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8281573f1250662875abe7a786dc24d4393a1ed45af747c3b8550d1a1f4917827374c1cfabb156e48aa21864e2a3cedace92890cce92b4f36494bee2127ebd64
|
7
|
+
data.tar.gz: 2a0fce9375da89171919edf2c34ec65f5077124aab6437e84e1168452886952c429717db0c31488082a34807f4413621f39a55160252695c3172a9e22f1e0da4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Manifest
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
ext/extconf.rb
|
2
|
+
ext/idgen.c
|
3
|
+
ext/idgen.h
|
4
|
+
ext/rlibidgen32.i
|
5
|
+
ext/rlibidgen32_wrap.c
|
6
|
+
idgen32.gemspec
|
7
|
+
init.rb
|
8
|
+
lib/idgen32.rb
|
9
|
+
Manifest
|
10
|
+
Rakefile
|
11
|
+
README.rdoc
|
12
|
+
test/bench.rb
|
13
|
+
test/test_helper.rb
|
14
|
+
test/unit/binding.rb
|
15
|
+
test/unit/test_idgen32.rb
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Idgen32
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/hellvinz/idgen32.png)](https://travis-ci.org/hellvinz/idgen32)
|
4
|
+
|
5
|
+
Idgen32 functions provide a facility to generate a stream of 32-bit
|
6
|
+
numbers that are strongly unpredictable and have a repetition cycle close
|
7
|
+
to 2^32. Such numbers are useful as protocol identifiers where there are
|
8
|
+
negative consequences to reusing an ID within a short time period, as may
|
9
|
+
happen if they are simply assigned at random.
|
10
|
+
|
11
|
+
Note that this function will never return 0 as it often has a special
|
12
|
+
meaning in network protocols.
|
13
|
+
|
14
|
+
## DEPENDENCIES
|
15
|
+
|
16
|
+
No dependencies. Require a compiler and the standard C library.
|
17
|
+
|
18
|
+
If you want to run the tests you'll need to have the following dependencies installed:
|
19
|
+
|
20
|
+
* minitest
|
21
|
+
|
22
|
+
## USAGE
|
23
|
+
|
24
|
+
```
|
25
|
+
require 'idgen32'
|
26
|
+
|
27
|
+
Idgen32.instance.generate
|
28
|
+
```
|
29
|
+
|
30
|
+
## LICENSE:
|
31
|
+
|
32
|
+
Copyright (c) 2008 Vincent Hellot
|
33
|
+
|
34
|
+
Parts of the C extension are borrowed from the OpenBsd project.
|
35
|
+
crypto/idgen.h
|
36
|
+
crypto/idgen.c
|
37
|
+
|
38
|
+
Copyright (c) 2008 Damien Miller <djm@mindrot.org>
|
39
|
+
|
40
|
+
Permission to use, copy, modify, and distribute this software for any
|
41
|
+
purpose with or without fee is hereby granted, provided that the above
|
42
|
+
copyright notice and this permission notice appear in all copies.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
45
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
46
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
47
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
48
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
49
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
50
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
51
|
+
|
52
|
+
IDGEN32: non-repeating ID generation covering an almost maximal
|
53
|
+
32 bit range.
|
54
|
+
Based on public domain SKIP32 by Greg Rose.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rdoc/task'
|
5
|
+
|
6
|
+
CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
|
7
|
+
CLEAN.include('ext/**/Makefile')
|
8
|
+
CLOBBER.include('lib/*{.so,.bundle}')
|
9
|
+
|
10
|
+
require 'rake/extensiontask'
|
11
|
+
|
12
|
+
Rake::ExtensionTask.new('rlibidgen32')
|
13
|
+
|
14
|
+
Rake::TestTask.new do |t|
|
15
|
+
t.libs << 'test'
|
16
|
+
t.test_files = FileList['test/*_test.rb']
|
17
|
+
t.verbose = true
|
18
|
+
end
|
19
|
+
|
20
|
+
task :bench do
|
21
|
+
ruby "test/bench.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
RDoc::Task.new do |rdoc|
|
25
|
+
rdoc.main = "README.md"
|
26
|
+
rdoc.rdoc_files.include("README.md", "lib/*.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
task :default => [:test]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
swig = [ 'swig2', 'swig2.0', 'swig' ].select { |swig_name| find_executable(swig_name) }.first
|
4
|
+
|
5
|
+
if swig
|
6
|
+
$stdout.write "Using '#{swig}' to generate wrapper code... "
|
7
|
+
`#{swig} -ruby #{File.dirname(File.realpath(__FILE__))}/rlibidgen32.i`
|
8
|
+
$stdout.write "done\n"
|
9
|
+
else
|
10
|
+
$stderr.write "You need SWIG to compile this extension.\n"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
if /linux$/ =~ RUBY_PLATFORM
|
15
|
+
if !find_header('bsd/stdlib.h') or !find_library('bsd', 'arc4random')
|
16
|
+
$stderr.write 'function arc4random is needed please install libbsd-dev'
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
have_func('arc4random_buf')
|
22
|
+
|
23
|
+
create_makefile 'rlibidgen32'
|
@@ -0,0 +1,157 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2008 Damien Miller <djm@mindrot.org>
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/*
|
18
|
+
* IDGEN32: non-repeating ID generation covering an almost maximal 32-bit
|
19
|
+
* range.
|
20
|
+
*
|
21
|
+
* IDGEN32 is based on public domain SKIP32 by Greg Rose.
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include <stdlib.h>
|
25
|
+
#include <sys/types.h>
|
26
|
+
#include <sys/time.h>
|
27
|
+
#include <strings.h>
|
28
|
+
|
29
|
+
#include "idgen.h"
|
30
|
+
|
31
|
+
static const u_int8_t idgen32_ftable[256] = {
|
32
|
+
0xa3, 0xd7, 0x09, 0x83, 0xf8, 0x48, 0xf6, 0xf4,
|
33
|
+
0xb3, 0x21, 0x15, 0x78, 0x99, 0xb1, 0xaf, 0xf9,
|
34
|
+
0xe7, 0x2d, 0x4d, 0x8a, 0xce, 0x4c, 0xca, 0x2e,
|
35
|
+
0x52, 0x95, 0xd9, 0x1e, 0x4e, 0x38, 0x44, 0x28,
|
36
|
+
0x0a, 0xdf, 0x02, 0xa0, 0x17, 0xf1, 0x60, 0x68,
|
37
|
+
0x12, 0xb7, 0x7a, 0xc3, 0xe9, 0xfa, 0x3d, 0x53,
|
38
|
+
0x96, 0x84, 0x6b, 0xba, 0xf2, 0x63, 0x9a, 0x19,
|
39
|
+
0x7c, 0xae, 0xe5, 0xf5, 0xf7, 0x16, 0x6a, 0xa2,
|
40
|
+
0x39, 0xb6, 0x7b, 0x0f, 0xc1, 0x93, 0x81, 0x1b,
|
41
|
+
0xee, 0xb4, 0x1a, 0xea, 0xd0, 0x91, 0x2f, 0xb8,
|
42
|
+
0x55, 0xb9, 0xda, 0x85, 0x3f, 0x41, 0xbf, 0xe0,
|
43
|
+
0x5a, 0x58, 0x80, 0x5f, 0x66, 0x0b, 0xd8, 0x90,
|
44
|
+
0x35, 0xd5, 0xc0, 0xa7, 0x33, 0x06, 0x65, 0x69,
|
45
|
+
0x45, 0x00, 0x94, 0x56, 0x6d, 0x98, 0x9b, 0x76,
|
46
|
+
0x97, 0xfc, 0xb2, 0xc2, 0xb0, 0xfe, 0xdb, 0x20,
|
47
|
+
0xe1, 0xeb, 0xd6, 0xe4, 0xdd, 0x47, 0x4a, 0x1d,
|
48
|
+
0x42, 0xed, 0x9e, 0x6e, 0x49, 0x3c, 0xcd, 0x43,
|
49
|
+
0x27, 0xd2, 0x07, 0xd4, 0xde, 0xc7, 0x67, 0x18,
|
50
|
+
0x89, 0xcb, 0x30, 0x1f, 0x8d, 0xc6, 0x8f, 0xaa,
|
51
|
+
0xc8, 0x74, 0xdc, 0xc9, 0x5d, 0x5c, 0x31, 0xa4,
|
52
|
+
0x70, 0x88, 0x61, 0x2c, 0x9f, 0x0d, 0x2b, 0x87,
|
53
|
+
0x50, 0x82, 0x54, 0x64, 0x26, 0x7d, 0x03, 0x40,
|
54
|
+
0x34, 0x4b, 0x1c, 0x73, 0xd1, 0xc4, 0xfd, 0x3b,
|
55
|
+
0xcc, 0xfb, 0x7f, 0xab, 0xe6, 0x3e, 0x5b, 0xa5,
|
56
|
+
0xad, 0x04, 0x23, 0x9c, 0x14, 0x51, 0x22, 0xf0,
|
57
|
+
0x29, 0x79, 0x71, 0x7e, 0xff, 0x8c, 0x0e, 0xe2,
|
58
|
+
0x0c, 0xef, 0xbc, 0x72, 0x75, 0x6f, 0x37, 0xa1,
|
59
|
+
0xec, 0xd3, 0x8e, 0x62, 0x8b, 0x86, 0x10, 0xe8,
|
60
|
+
0x08, 0x77, 0x11, 0xbe, 0x92, 0x4f, 0x24, 0xc5,
|
61
|
+
0x32, 0x36, 0x9d, 0xcf, 0xf3, 0xa6, 0xbb, 0xac,
|
62
|
+
0x5e, 0x6c, 0xa9, 0x13, 0x57, 0x25, 0xb5, 0xe3,
|
63
|
+
0xbd, 0xa8, 0x3a, 0x01, 0x05, 0x59, 0x2a, 0x46
|
64
|
+
};
|
65
|
+
|
66
|
+
#ifndef HAVE_ARC4RANDOM_BUF
|
67
|
+
void
|
68
|
+
arc4random_buf(void *_buf, size_t n)
|
69
|
+
{
|
70
|
+
size_t i;
|
71
|
+
u_int32_t r = 0;
|
72
|
+
char *buf = (char *)_buf;
|
73
|
+
|
74
|
+
for (i = 0; i < n; i++) {
|
75
|
+
if (i % 4 == 0)
|
76
|
+
r = arc4random();
|
77
|
+
buf[i] = r & 0xff;
|
78
|
+
r >>= 8;
|
79
|
+
}
|
80
|
+
i = r = 0;
|
81
|
+
}
|
82
|
+
#endif /* !HAVE_ARC4RANDOM_BUF */
|
83
|
+
|
84
|
+
|
85
|
+
static u_int16_t
|
86
|
+
idgen32_g(u_int8_t *key, int k, u_int16_t w)
|
87
|
+
{
|
88
|
+
u_int8_t g1, g2, g3, g4, g5, g6;
|
89
|
+
u_int o = k * 4;
|
90
|
+
|
91
|
+
g1 = (w >> 8) & 0xff;
|
92
|
+
g2 = w & 0xff;
|
93
|
+
|
94
|
+
g3 = idgen32_ftable[g2 ^ key[o++ & (IDGEN32_KEYLEN - 1)]] ^ g1;
|
95
|
+
g4 = idgen32_ftable[g3 ^ key[o++ & (IDGEN32_KEYLEN - 1)]] ^ g2;
|
96
|
+
g5 = idgen32_ftable[g4 ^ key[o++ & (IDGEN32_KEYLEN - 1)]] ^ g3;
|
97
|
+
g6 = idgen32_ftable[g5 ^ key[o++ & (IDGEN32_KEYLEN - 1)]] ^ g4;
|
98
|
+
|
99
|
+
return (g5 << 8) | g6;
|
100
|
+
}
|
101
|
+
|
102
|
+
static u_int32_t
|
103
|
+
idgen32_permute(struct Idgen32_ctx *ctx, u_int32_t in)
|
104
|
+
{
|
105
|
+
u_int i, r;
|
106
|
+
u_int16_t wl, wr;
|
107
|
+
|
108
|
+
wl = (in >> 16) & 0x7fff;
|
109
|
+
wr = in & 0xffff;
|
110
|
+
|
111
|
+
/* Doubled up rounds, with an odd round at the end to swap */
|
112
|
+
for (i = r = 0; i < IDGEN32_ROUNDS / 2; ++i) {
|
113
|
+
wr ^= (idgen32_g(ctx->id32_key, r, wl) ^ r);
|
114
|
+
r++;
|
115
|
+
wl ^= (idgen32_g(ctx->id32_key, r, wr) ^ r) & 0x7fff;
|
116
|
+
r++;
|
117
|
+
}
|
118
|
+
wr ^= (idgen32_g(ctx->id32_key, r, wl) ^ r);
|
119
|
+
|
120
|
+
return (wl << 16) | wr;
|
121
|
+
}
|
122
|
+
|
123
|
+
static void
|
124
|
+
idgen32_rekey(struct Idgen32_ctx *ctx)
|
125
|
+
{
|
126
|
+
ctx->id32_counter = 0;
|
127
|
+
ctx->id32_hibit ^= 0x80000000;
|
128
|
+
ctx->id32_offset = arc4random();
|
129
|
+
arc4random_buf(ctx->id32_key, sizeof(ctx->id32_key));
|
130
|
+
ctx->id32_rekey_time = time(NULL) + IDGEN32_REKEY_TIME;
|
131
|
+
}
|
132
|
+
|
133
|
+
void
|
134
|
+
idgen32_init(struct Idgen32_ctx *ctx)
|
135
|
+
{
|
136
|
+
bzero(ctx, sizeof(*ctx));
|
137
|
+
ctx->id32_hibit = arc4random() & 0x80000000;
|
138
|
+
idgen32_rekey(ctx);
|
139
|
+
}
|
140
|
+
|
141
|
+
u_int32_t
|
142
|
+
idgen32(struct Idgen32_ctx *ctx)
|
143
|
+
{
|
144
|
+
u_int32_t ret;
|
145
|
+
|
146
|
+
do {
|
147
|
+
/* Rekey a little early to avoid "card counting" attack */
|
148
|
+
if (ctx->id32_counter > IDGEN32_REKEY_LIMIT ||
|
149
|
+
ctx->id32_rekey_time < time(NULL))
|
150
|
+
idgen32_rekey(ctx);
|
151
|
+
ret = ctx->id32_hibit | idgen32_permute(ctx,
|
152
|
+
(ctx->id32_offset + ctx->id32_counter++) & 0x7fffffff);
|
153
|
+
} while (ret == 0); /* Zero IDs are often special, so avoid */
|
154
|
+
|
155
|
+
return ret;
|
156
|
+
}
|
157
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/* $OpenBSD: idgen.h,v 1.3 2013/06/05 05:45:54 djm Exp $ */
|
2
|
+
/*
|
3
|
+
* Copyright (c) 2008 Damien Miller <djm@mindrot.org>
|
4
|
+
*
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
8
|
+
*
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
15
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#define IDGEN32_ROUNDS 31
|
19
|
+
#define IDGEN32_KEYLEN 32
|
20
|
+
#define IDGEN32_REKEY_LIMIT 0x60000000
|
21
|
+
#define IDGEN32_REKEY_TIME 600
|
22
|
+
|
23
|
+
struct Idgen32_ctx {
|
24
|
+
u_int32_t id32_counter;
|
25
|
+
u_int32_t id32_offset;
|
26
|
+
u_int32_t id32_hibit;
|
27
|
+
u_int8_t id32_key[IDGEN32_KEYLEN];
|
28
|
+
time_t id32_rekey_time;
|
29
|
+
};
|
30
|
+
|
31
|
+
void idgen32_init(struct Idgen32_ctx *);
|
32
|
+
u_int32_t idgen32(struct Idgen32_ctx *);
|
33
|
+
|
data/idgen32.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require File.expand_path('../lib/idgen32/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{idgen32}
|
8
|
+
s.version = Idgen32::VERSION
|
9
|
+
s.required_rubygems_version = ">= 2.0"
|
10
|
+
s.authors = ["Vincent Hellot"]
|
11
|
+
s.email = %q{hellvinz@gmail.com}
|
12
|
+
s.date = %q{2008-11-23}
|
13
|
+
s.summary = %q{Non-repeating ID generation}
|
14
|
+
s.description = %q{non-repeating ID generation covering an almost maximal 32-bit range.}
|
15
|
+
s.extensions = ["ext/rlibidgen32/extconf.rb"]
|
16
|
+
s.extra_rdoc_files = ["README.md"]
|
17
|
+
s.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
18
|
+
s.executables = s.files.grep(/^bin\//).map { |f| File.basename(f) }
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.homepage = %q{http://github.com/hellvinz/idgen32}
|
21
|
+
s.rdoc_options = ["--line-numbers", "--inline-source","--exclude", "ext/*", "--title", "Idgen32", "--main", "README.md"]
|
22
|
+
s.require_paths = ["lib", "ext"]
|
23
|
+
s.test_files = ["test/test_helper.rb", "test/idgen32_test.rb", "test/binding_test.rb", "test/bench.rb"]
|
24
|
+
|
25
|
+
s.add_development_dependency 'rake-compiler', '~>0.9.5'
|
26
|
+
s.add_development_dependency 'rake', '>= 0.8.7'
|
27
|
+
s.add_development_dependency 'minitest', '~> 5.0', '>= 5.0.0'
|
28
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'idgen32'
|
data/lib/idgen32.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'rlibidgen32'
|
3
|
+
|
4
|
+
class Idgen32
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def initialize #:nodoc:
|
8
|
+
@struct = Rlibidgen32::Idgen32_ctx.new
|
9
|
+
Rlibidgen32.idgen32_init(@struct)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Generate the unique id
|
13
|
+
def generate
|
14
|
+
Rlibidgen32.idgen32(@struct)
|
15
|
+
end
|
16
|
+
end
|
data/test/bench.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby -wU
|
2
|
+
|
3
|
+
HERE = File.dirname(__FILE__)
|
4
|
+
$LOAD_PATH << "#{HERE}/../lib/"
|
5
|
+
require 'idgen32'
|
6
|
+
|
7
|
+
require 'benchmark'
|
8
|
+
require 'rubygems'
|
9
|
+
|
10
|
+
|
11
|
+
class Bench
|
12
|
+
def run
|
13
|
+
benchmark
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def benchmark
|
18
|
+
Benchmark.bm(30) do |x|
|
19
|
+
@m = Idgen32.instance
|
20
|
+
n = 1000000
|
21
|
+
x.report("idgen32:#{n}:generate") do
|
22
|
+
n.times {@m.generate}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Bench.new.run
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idgen32
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Hellot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2008-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.5
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.7
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 5.0.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '5.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.0.0
|
61
|
+
description: non-repeating ID generation covering an almost maximal 32-bit range.
|
62
|
+
email: hellvinz@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions:
|
65
|
+
- ext/rlibidgen32/extconf.rb
|
66
|
+
extra_rdoc_files:
|
67
|
+
- README.md
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- ".travis.yml"
|
71
|
+
- Gemfile
|
72
|
+
- Manifest
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- ext/rlibidgen32/extconf.rb
|
76
|
+
- ext/rlibidgen32/idgen.c
|
77
|
+
- ext/rlibidgen32/idgen.h
|
78
|
+
- ext/rlibidgen32/rlibidgen32.i
|
79
|
+
- idgen32.gemspec
|
80
|
+
- init.rb
|
81
|
+
- lib/idgen32.rb
|
82
|
+
- lib/idgen32/version.rb
|
83
|
+
- test/bench.rb
|
84
|
+
- test/binding_test.rb
|
85
|
+
- test/idgen32_test.rb
|
86
|
+
- test/test_helper.rb
|
87
|
+
homepage: http://github.com/hellvinz/idgen32
|
88
|
+
licenses: []
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options:
|
92
|
+
- "--line-numbers"
|
93
|
+
- "--inline-source"
|
94
|
+
- "--exclude"
|
95
|
+
- ext/*
|
96
|
+
- "--title"
|
97
|
+
- Idgen32
|
98
|
+
- "--main"
|
99
|
+
- README.md
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
- ext
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '2.0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Non-repeating ID generation
|
119
|
+
test_files:
|
120
|
+
- test/test_helper.rb
|
121
|
+
- test/idgen32_test.rb
|
122
|
+
- test/binding_test.rb
|
123
|
+
- test/bench.rb
|