hitimes 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +0,0 @@
1
- package hitimes;
2
-
3
- import java.io.IOException;
4
-
5
- import org.jruby.Ruby;
6
-
7
- import org.jruby.runtime.load.BasicLibraryService;
8
-
9
- public class HitimesService implements BasicLibraryService {
10
- public boolean basicLoad( final Ruby runtime ) throws IOException {
11
- Hitimes.createHitimesModule( runtime );
12
- return true;
13
- }
14
- }
15
-
16
-
@@ -1,112 +0,0 @@
1
- package hitimes;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyClass;
5
- import org.jruby.RubyObject;
6
-
7
- import org.jruby.RubyNumeric;
8
- import org.jruby.runtime.builtin.IRubyObject;
9
- import org.jruby.runtime.ObjectAllocator;
10
-
11
- import org.jruby.anno.JRubyMethod;
12
- import org.jruby.anno.JRubyClass;
13
-
14
- @JRubyClass( name = "Hitimes::Stats" )
15
- public class HitimesStats extends RubyObject {
16
-
17
- private double min = 0.0;
18
- private double max = 0.0;
19
- private double sum = 0.0;
20
- private double sumsq = 0.0;
21
- private long count = 0;
22
-
23
- public static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
24
- public IRubyObject allocate(Ruby runtime, RubyClass klass) {
25
- return new HitimesStats( runtime, klass );
26
- }
27
- };
28
-
29
- public HitimesStats( Ruby runtime, RubyClass klass ) {
30
- super( runtime, klass );
31
- }
32
-
33
- @JRubyMethod( name = "update", required = 1, argTypes = RubyNumeric.class )
34
- public IRubyObject update( IRubyObject val ) {
35
- double v = RubyNumeric.num2dbl( val );
36
-
37
- if ( 0 == this.count ) {
38
- this.min = this.max = v;
39
- } else {
40
- this.min = ( v < this.min ) ? v : this.min;
41
- this.max = ( v > this.max ) ? v : this.max;
42
- }
43
-
44
- this.count += 1;
45
- this.sum += v;
46
- this.sumsq += (v * v);
47
-
48
- return val;
49
- }
50
-
51
- @JRubyMethod( name = "mean" )
52
- public IRubyObject mean() {
53
- double mean = 0.0;
54
-
55
- if ( this.count > 0 ) {
56
- mean = this.sum / this.count;
57
- }
58
-
59
- return getRuntime().newFloat( mean );
60
- }
61
-
62
-
63
- @JRubyMethod( name = "rate" )
64
- public IRubyObject rate() {
65
- double rate = 0.0;
66
-
67
- if ( this.sum > 0.0 ) {
68
- rate = this.count / this.sum ;
69
- }
70
-
71
- return getRuntime().newFloat( rate );
72
- }
73
-
74
- @JRubyMethod( name = "stddev" )
75
- public IRubyObject stddev() {
76
- double stddev = 0.0;
77
-
78
- if ( this.count > 1 ) {
79
- double sq_sum = this.sum * this.sum;
80
- stddev = Math.sqrt( ( this.sumsq - ( sq_sum / this.count ) ) / ( this.count - 1 ) );
81
- }
82
- return getRuntime().newFloat( stddev );
83
- }
84
-
85
-
86
- @JRubyMethod( name = "min" )
87
- public IRubyObject min() {
88
- return getRuntime().newFloat( this.min );
89
- }
90
-
91
- @JRubyMethod( name = "max" )
92
- public IRubyObject max() {
93
- return getRuntime().newFloat( this.max );
94
- }
95
-
96
- @JRubyMethod( name = "sum" )
97
- public IRubyObject sum() {
98
- return getRuntime().newFloat( this.sum );
99
- }
100
-
101
- @JRubyMethod( name = "sumsq" )
102
- public IRubyObject sumsq() {
103
- return getRuntime().newFloat( this.sumsq );
104
- }
105
-
106
- @JRubyMethod( name = "count" )
107
- public IRubyObject count() {
108
- return getRuntime().newFixnum( this.count );
109
- }
110
- }
111
-
112
-
@@ -1,38 +0,0 @@
1
- # To be used if the gem has extensions.
2
- # If this task set is inclueded then you will need to also have
3
- #
4
- # spec.add_development_dependency( 'rake-compiler', '~> 0.8.1' )
5
- #
6
- # in your top level rakefile
7
- begin
8
- require 'rake/extensiontask'
9
- require 'rake/javaextensiontask'
10
-
11
- if RUBY_PLATFORM == "java" then
12
-
13
- Rake::JavaExtensionTask.new( This.name) do |ext|
14
- ext.ext_dir = File.join( 'ext', This.name, "java" )
15
- ext.lib_dir = File.join( 'lib', This.name )
16
- ext.gem_spec = This.java_gemspec
17
- end
18
-
19
- else
20
-
21
- Rake::ExtensionTask.new( This.name ) do |ext|
22
- ext.ext_dir = File.join( 'ext', This.name, "c" )
23
- ext.lib_dir = File.join( 'lib', This.name )
24
- ext.gem_spec = This.ruby_gemspec
25
-
26
- ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
27
- ext.cross_platform = %w[x86-mingw32 x64-mingw32] # forces the Windows platform instead of the default one
28
- # configure options only for cross compile
29
- end
30
- end
31
-
32
- task :test_requirements => :compile
33
- rescue LoadError
34
- This.task_warning( 'extension' )
35
- end
36
-
37
- CLOBBER << FileList["lib/**/*.{jar,so,bundle}"]
38
- CLOBBER << FileList["lib/#{This.name}/{1,2}.*/"]