d_heap 0.2.2 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +2 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +40 -1
- data/.yardopts +10 -0
- data/CHANGELOG.md +76 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +26 -1
- data/N +7 -0
- data/README.md +358 -147
- data/benchmarks/perf.rb +29 -0
- data/benchmarks/push_n.yml +35 -0
- data/benchmarks/push_n_pop_n.yml +52 -0
- data/benchmarks/push_pop.yml +32 -0
- data/benchmarks/stackprof.rb +31 -0
- data/bin/bench_charts +13 -0
- data/bin/bench_n +7 -0
- data/bin/benchmark-driver +29 -0
- data/bin/benchmarks +10 -0
- data/bin/profile +10 -0
- data/d_heap.gemspec +5 -2
- data/docs/benchmarks-2.txt +75 -0
- data/docs/benchmarks-mem.txt +39 -0
- data/docs/benchmarks.txt +515 -0
- data/docs/profile.txt +392 -0
- data/ext/d_heap/d_heap.c +824 -246
- data/ext/d_heap/extconf.rb +16 -3
- data/images/push_n.png +0 -0
- data/images/push_n_pop_n.png +0 -0
- data/images/push_pop.png +0 -0
- data/images/wikipedia-min-heap.png +0 -0
- data/lib/benchmark_driver/runner/ips_zero_fail.rb +158 -0
- data/lib/d_heap.rb +92 -3
- data/lib/d_heap/benchmarks.rb +112 -0
- data/lib/d_heap/benchmarks/benchmarker.rb +116 -0
- data/lib/d_heap/benchmarks/implementations.rb +224 -0
- data/lib/d_heap/benchmarks/profiler.rb +71 -0
- data/lib/d_heap/benchmarks/rspec_matchers.rb +352 -0
- data/lib/d_heap/version.rb +1 -1
- metadata +60 -6
- data/ext/d_heap/d_heap.h +0 -65
data/lib/d_heap/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: d_heap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nicholas a. evans
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark_driver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-prof
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: |
|
14
42
|
A C extension implementation of a d-ary heap data structure, suitable for
|
15
43
|
use in e.g. priority queues or Djikstra's algorithm.
|
@@ -25,22 +53,48 @@ files:
|
|
25
53
|
- ".rspec"
|
26
54
|
- ".rubocop.yml"
|
27
55
|
- ".travis.yml"
|
56
|
+
- ".yardopts"
|
57
|
+
- CHANGELOG.md
|
28
58
|
- CODE_OF_CONDUCT.md
|
29
59
|
- Gemfile
|
30
60
|
- Gemfile.lock
|
31
61
|
- LICENSE.txt
|
62
|
+
- N
|
32
63
|
- README.md
|
33
64
|
- Rakefile
|
65
|
+
- benchmarks/perf.rb
|
66
|
+
- benchmarks/push_n.yml
|
67
|
+
- benchmarks/push_n_pop_n.yml
|
68
|
+
- benchmarks/push_pop.yml
|
69
|
+
- benchmarks/stackprof.rb
|
70
|
+
- bin/bench_charts
|
71
|
+
- bin/bench_n
|
72
|
+
- bin/benchmark-driver
|
73
|
+
- bin/benchmarks
|
34
74
|
- bin/console
|
75
|
+
- bin/profile
|
35
76
|
- bin/rake
|
36
77
|
- bin/rspec
|
37
78
|
- bin/rubocop
|
38
79
|
- bin/setup
|
39
80
|
- d_heap.gemspec
|
81
|
+
- docs/benchmarks-2.txt
|
82
|
+
- docs/benchmarks-mem.txt
|
83
|
+
- docs/benchmarks.txt
|
84
|
+
- docs/profile.txt
|
40
85
|
- ext/d_heap/d_heap.c
|
41
|
-
- ext/d_heap/d_heap.h
|
42
86
|
- ext/d_heap/extconf.rb
|
87
|
+
- images/push_n.png
|
88
|
+
- images/push_n_pop_n.png
|
89
|
+
- images/push_pop.png
|
90
|
+
- images/wikipedia-min-heap.png
|
91
|
+
- lib/benchmark_driver/runner/ips_zero_fail.rb
|
43
92
|
- lib/d_heap.rb
|
93
|
+
- lib/d_heap/benchmarks.rb
|
94
|
+
- lib/d_heap/benchmarks/benchmarker.rb
|
95
|
+
- lib/d_heap/benchmarks/implementations.rb
|
96
|
+
- lib/d_heap/benchmarks/profiler.rb
|
97
|
+
- lib/d_heap/benchmarks/rspec_matchers.rb
|
44
98
|
- lib/d_heap/version.rb
|
45
99
|
homepage: https://github.com/nevans/d_heap
|
46
100
|
licenses:
|
@@ -48,7 +102,7 @@ licenses:
|
|
48
102
|
metadata:
|
49
103
|
homepage_uri: https://github.com/nevans/d_heap
|
50
104
|
source_code_uri: https://github.com/nevans/d_heap
|
51
|
-
changelog_uri: https://github.com/nevans/d_heap/blob/master/
|
105
|
+
changelog_uri: https://github.com/nevans/d_heap/blob/master/CHANGELOG.md
|
52
106
|
post_install_message:
|
53
107
|
rdoc_options: []
|
54
108
|
require_paths:
|
@@ -57,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
111
|
requirements:
|
58
112
|
- - ">="
|
59
113
|
- !ruby/object:Gem::Version
|
60
|
-
version: 2.
|
114
|
+
version: 2.4.0
|
61
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
116
|
requirements:
|
63
117
|
- - ">="
|
data/ext/d_heap/d_heap.h
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
#ifndef D_HEAP_H
|
2
|
-
#define D_HEAP_H 1
|
3
|
-
|
4
|
-
#include "ruby.h"
|
5
|
-
|
6
|
-
// d=4 uses the fewest comparisons for insert + delete-min (in the worst case).
|
7
|
-
#define DHEAP_DEFAULT_D 4
|
8
|
-
|
9
|
-
// This is a somewhat arbitary maximum. But benefits from more leaf nodes
|
10
|
-
// are very unlikely to outweigh the increasinly higher number of worst-case
|
11
|
-
// comparisons as d gets further from 4.
|
12
|
-
#define DHEAP_MAX_D 32
|
13
|
-
|
14
|
-
VALUE rb_cDHeap;
|
15
|
-
|
16
|
-
#define CMP_LT(a, b) (optimized_cmp(a, b) < 0)
|
17
|
-
#define CMP_LTE(a, b) (optimized_cmp(a, b) <= 0)
|
18
|
-
#define CMP_GT(a, b) (optimized_cmp(a, b) > 0)
|
19
|
-
#define CMP_GTE(a, b) (optimized_cmp(a, b) >= 0)
|
20
|
-
|
21
|
-
// <=>
|
22
|
-
ID id_cmp;
|
23
|
-
|
24
|
-
// from internal/compar.h
|
25
|
-
#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
|
26
|
-
|
27
|
-
/*
|
28
|
-
* short-circuit evaluation for a few basic types.
|
29
|
-
*
|
30
|
-
* Only Integer, Float, and String are optimized,
|
31
|
-
* and only when both arguments are the same type.
|
32
|
-
*/
|
33
|
-
static inline int
|
34
|
-
optimized_cmp(VALUE a, VALUE b) {
|
35
|
-
if (a == b) // Fixnum equality and object equality
|
36
|
-
return 0;
|
37
|
-
if (FIXNUM_P(a) && FIXNUM_P(b))
|
38
|
-
return (FIX2LONG(a) < FIX2LONG(b)) ? -1 : 1;
|
39
|
-
if (RB_FLOAT_TYPE_P(a) && RB_FLOAT_TYPE_P(b))
|
40
|
-
{
|
41
|
-
double x, y;
|
42
|
-
x = RFLOAT_VALUE(a);
|
43
|
-
y = RFLOAT_VALUE(b);
|
44
|
-
if (isnan(x) || isnan(y)) rb_cmperr(a, b); // raise ArgumentError
|
45
|
-
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
46
|
-
}
|
47
|
-
if (RB_TYPE_P(a, T_BIGNUM) && RB_TYPE_P(b, T_BIGNUM))
|
48
|
-
return FIX2INT(rb_big_cmp(a, b));
|
49
|
-
if (STRING_P(a) && STRING_P(b))
|
50
|
-
return rb_str_cmp(a, b);
|
51
|
-
|
52
|
-
// give up on an optimized version and just call (a <=> b)
|
53
|
-
return rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b);
|
54
|
-
}
|
55
|
-
|
56
|
-
#ifdef __D_HEAP_DEBUG
|
57
|
-
#define debug(v) { \
|
58
|
-
ID sym_puts = rb_intern("puts"); \
|
59
|
-
rb_funcall(rb_mKernel, sym_puts, 1, v); \
|
60
|
-
}
|
61
|
-
#else
|
62
|
-
#define debug(v)
|
63
|
-
#endif
|
64
|
-
|
65
|
-
#endif /* D_HEAP_H */
|