hipe-simplebtree 0.0.0

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/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ coverage
2
+ .DS_Store
3
+ pkg
4
+ doc
5
+ ri
6
+ email.txt
7
+ .svn
8
+ log
9
+ .project
10
+ .loadpath
11
+ *.swp
12
+ results
13
+ test_apps
14
+ *.tmproj
15
+ *.log
16
+ *.pid
17
+ bin
18
+ vendor/gems
19
+ eraseme.*
20
+ tmp.*
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.0.0 / 2009-11-20
2
+ * 1 major enhancement
3
+ * existence (apologies to webrat)
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Mark Meves
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.txt ADDED
@@ -0,0 +1,9 @@
1
+ This is just for trying to get my first gem to work.
2
+
3
+ If you have checked this out from git (the "sources",)
4
+ try:
5
+ $ thor default:gemspec
6
+ $ thor default:build
7
+ $ sudo thor default:install
8
+
9
+ (if you don't have thor, it is a gem and it is like rake.)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+
2
+ # require 'spec'
3
+ require 'spec/rake/spectask'
4
+ require 'spec/rake/verify_rcov'
5
+
6
+ desc "Run API and Core specs"
7
+ Spec::Rake::SpecTask.new do |t|
8
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
9
+ t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
10
+ end
11
+
data/Thorfile ADDED
@@ -0,0 +1,116 @@
1
+ # this file was originally copy-pasted from webrat's Thorfile. Thank you Bryan Helmkamp!
2
+ module GemHelpers
3
+
4
+ def generate_gemspec
5
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
6
+ require "cli"
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'hipe-simplebtree'
10
+ s.version = Hipe::Cli::VERSION
11
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
12
+ s.author = "Mark Meves"
13
+ s.email = "mark.meves@gmail.com"
14
+ s.homepage = "http://github.com/hipe/hipe-simplebtree"
15
+ s.date = %q{2009-11-20}
16
+ s.summary = %q{Experiment}
17
+ s.description = <<-EOS.strip
18
+ just playing around
19
+ EOS
20
+ # s.rubyforge_project = "webrat"
21
+
22
+ require "git"
23
+ repo = Git.open(".")
24
+
25
+ s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files)
26
+ s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)
27
+
28
+ s.has_rdoc = 'yard' # trying out arg[0]/lsegal's doc tool
29
+ #s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt History.txt]
30
+ #s.extra_rdoc_files = %w[MIT-LICENSE.txt History.txt]
31
+
32
+ #s.add_dependency "nokogiri", ">= 1.2.0"
33
+ #s.add_dependency "rack", ">= 1.0"
34
+ end
35
+ end
36
+
37
+ def normalize_files(array)
38
+ # only keep files, no directories, and sort
39
+ array.select do |path|
40
+ File.file?(path)
41
+ end.sort
42
+ end
43
+
44
+ # Adds extra space when outputting an array. This helps create better version
45
+ # control diffs, because otherwise it is all on the same line.
46
+ def prettyify_array(gemspec_ruby, array_name)
47
+ gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
48
+ leadin, files = match[0..-2].split("[")
49
+ leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
50
+ end
51
+ end
52
+
53
+ def read_gemspec
54
+ @read_gemspec ||= eval(File.read("hipe-simplebtree.gemspec"))
55
+ end
56
+
57
+ def sh(command)
58
+ puts command
59
+ system command
60
+ end
61
+ end
62
+
63
+ class Default < Thor
64
+ include GemHelpers
65
+
66
+ desc "gemspec", "Regenerate hipe-simplebtree.gemspec"
67
+ def gemspec
68
+ File.open("hipe-simplebtree.gemspec", "w") do |file|
69
+ gemspec_ruby = generate_gemspec.to_ruby
70
+ gemspec_ruby = prettyify_array(gemspec_ruby, :files)
71
+ gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
72
+ gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)
73
+
74
+ file.write gemspec_ruby
75
+ end
76
+
77
+ puts "Wrote gemspec to hipe-simplebtree.gemspec"
78
+ read_gemspec.validate
79
+ end
80
+
81
+ desc "build", "Build a hipe-simplebtree gem"
82
+ def build
83
+ sh "gem build hipe-simplebtree.gemspec"
84
+ FileUtils.mkdir_p "pkg"
85
+ FileUtils.mv read_gemspec.file_name, "pkg"
86
+ end
87
+
88
+ desc "install", "Install the latest built gem"
89
+ def install
90
+ sh "gem install --local pkg/#{read_gemspec.file_name}"
91
+ end
92
+
93
+ desc "release", "Release the current branch to GitHub and Gemcutter"
94
+ def release
95
+ gemspec
96
+ build
97
+ Release.new.tag
98
+ Release.new.gem
99
+ end
100
+ end
101
+
102
+ class Release < Thor
103
+ include GemHelpers
104
+
105
+ desc "tag", "Tag the gem on the origin server"
106
+ def tag
107
+ release_tag = "v#{read_gemspec.version}"
108
+ sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
109
+ sh "git push origin #{release_tag}"
110
+ end
111
+
112
+ desc "gem", "Push the gem to Gemcutter"
113
+ def gem
114
+ sh "gem push pkg/#{read_gemspec.file_name}"
115
+ end
116
+ end
@@ -0,0 +1,37 @@
1
+ module Hipe
2
+ # Experimental *simple* b-tree -- the only purpose of this for now is to
3
+ # impleement a method for "find the index of the first element in the array
4
+ # that is greater than a provided element." It won't be efficient or useful
5
+ # for adding/removes lots of nodes, only for providing the above service.
6
+ # It is presumed that it will be slower than RBTrees (Red-Black tree), but
7
+ # faster than scanning all the elements of a sorted array to find this index.
8
+ class SimpleBTree
9
+
10
+ # @param [Array] array an array sorted or not sorted whose values represent the values
11
+ # of the nodes of the tree. Values need not be unique.
12
+ # @yield [left,right] a code block that stipulates your comparison
13
+ # algorithm for using in sorting, exactly like Array#sort
14
+ # @example
15
+ # tree = Hipe::SimpleBTree.new(['alpha','gamma','beta']){|x,y| x <=> y}
16
+ # puts tree.to_array
17
+ def initialize(array=nil, &sorter)
18
+ @array = array || []
19
+ @sorter = sorter || Proc.new {|left,right| left <=> right}
20
+ @sorted = false
21
+ end
22
+
23
+ def to_array
24
+ sort!
25
+ @array.clone
26
+ end
27
+
28
+ # @private
29
+ # left public for testing only
30
+ def sort!
31
+ unless @sorted
32
+ @array.sort!(&@sorter)
33
+ @sorted = true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ describe "btree" do
3
+ it "should be able to contruct an empty btree" do
4
+ tree = Hipe::SimpleBTree.new
5
+ end
6
+
7
+ it "should construct given a proc and sort a simple array" do
8
+ tree = Hipe::SimpleBTree.new(['gamma','alpha','beta']){|a,b| (a<=>b)*-1 }
9
+ arr = tree.to_array
10
+ arr.should == ['gamma','beta','alpha']
11
+ end
12
+
13
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --diff
2
+ --color
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "spec"
4
+ require "hipe-simplebtree"
5
+
6
+ # gem install redgreen for colored test output
7
+ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
8
+
9
+ mypath = File.expand_path(File.dirname(__FILE__) + "/../lib/")
10
+ $LOAD_PATH.unshift(mypath) unless $LOAD_PATH.include?(mypath)
11
+
12
+ AssertionFailedError = Test::Unit::AssertionFailedError rescue MiniTest::Assertion # ruby1.9 compat
13
+
14
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hipe-simplebtree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Meves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-20 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: just playing around
17
+ email: mark.meves@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - .gitignore
26
+ - History.txt
27
+ - LICENSE.txt
28
+ - README.txt
29
+ - Rakefile
30
+ - Thorfile
31
+ - lib/hipe-simplebtree.rb
32
+ - spec/public/simple_spec.rb
33
+ - spec/spec.opts
34
+ - spec/spec_helper.rb
35
+ has_rdoc: yard
36
+ homepage: http://github.com/hipe/hipe-simplebtree
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.1
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Experiment
63
+ test_files:
64
+ - spec/public/simple_spec.rb
65
+ - spec/spec_helper.rb