This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
name: test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby: [ 2.7, 3.0, head, jruby ]
|
||||
os: [ ubuntu ]
|
||||
|
||||
name: >-
|
||||
${{matrix.os}}-ruby-${{matrix.ruby}}
|
||||
runs-on: ${{matrix.os}}-latest
|
||||
continue-on-error: ${{matrix.ruby == 'head'}}
|
||||
|
||||
steps:
|
||||
- name: Check out
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Set up ruby and bundle
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{matrix.ruby}}
|
||||
bundler-cache: true
|
||||
|
||||
- name: Run test
|
||||
run: bundle exec rake test
|
||||
@@ -0,0 +1,9 @@
|
||||
/.bundle/
|
||||
/.yardoc
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
Gemfile.lock
|
||||
@@ -0,0 +1,23 @@
|
||||
# SortedSet Changelog
|
||||
|
||||
## 1.0.3 (2021-02-13)
|
||||
|
||||
* Enhancements
|
||||
* Switch back to the original [rbtree](https://rubygems.org/gems/rbtree) gem, which added support for Ruby >=3.0.
|
||||
|
||||
## 1.0.2 (2020-12-24)
|
||||
|
||||
* Enhancements
|
||||
* Switch to the [rbtree3](https://github.com/kyrylo/rbtree3) gem to support Ruby >=3.0.
|
||||
|
||||
## 1.0.1 (2020-12-22)
|
||||
|
||||
* Enhancements
|
||||
* Be a no-op library for JRuby, as it has its own version of Set and SortedSet.
|
||||
|
||||
## 1.0.0 (2020-12-22)
|
||||
|
||||
This is the first release of sorted_set as a gem. Here lists the changes since the version bundled with Ruby 2.7.
|
||||
|
||||
* Breaking Changes
|
||||
* The pure-ruby fallback implementation has been removed. It now requires an RBTree library to install and run.
|
||||
@@ -0,0 +1,7 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in sorted_set.gemspec
|
||||
gemspec
|
||||
|
||||
gem "rake", "~> 12.0"
|
||||
gem "test-unit"
|
||||
@@ -0,0 +1,24 @@
|
||||
Copyright (c) 2002-2020 Akinori MUSHA
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
@@ -0,0 +1,58 @@
|
||||
# SortedSet
|
||||
|
||||
SortedSet implements a Set whose elements are sorted in ascending
|
||||
order (according to the return values of their `<=>` methods) when
|
||||
iterating over them.
|
||||
|
||||
Every element in SortedSet must be *mutually comparable* to every
|
||||
other: comparison with `<=>` must not return nil for any pair of
|
||||
elements. Otherwise ArgumentError will be raised.
|
||||
|
||||
Currently this library does nothing for JRuby, as it has its own
|
||||
version of Set and SortedSet.
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'sorted_set'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
||||
$ bundle install
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install sorted_set
|
||||
|
||||
## Usage
|
||||
|
||||
```ruby
|
||||
require "sorted_set"
|
||||
|
||||
set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
|
||||
ary = []
|
||||
|
||||
set.each do |obj|
|
||||
ary << obj
|
||||
end
|
||||
|
||||
p ary # => [1, 2, 3, 4, 5, 6]
|
||||
|
||||
set2 = SortedSet.new([1, 2, "3"])
|
||||
set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/knu/sorted_set.
|
||||
|
||||
## License
|
||||
|
||||
The gem is available as open source under either the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
|
||||
@@ -0,0 +1,10 @@
|
||||
require "bundler/gem_tasks"
|
||||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << "test"
|
||||
t.libs << "lib"
|
||||
t.test_files = FileList["test/**/test_*.rb"]
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require "bundler/setup"
|
||||
require "sorted_set"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
||||
# (If you use this, don't forget to add pry to your Gemfile!)
|
||||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require "irb"
|
||||
IRB.start(__FILE__)
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
set -vx
|
||||
|
||||
bundle install
|
||||
|
||||
# Do any other automated setup that you need to do here
|
||||
@@ -0,0 +1,57 @@
|
||||
# :markup: markdown
|
||||
|
||||
require 'set'
|
||||
|
||||
return if defined?(JRUBY_VERSION)
|
||||
|
||||
require 'rbtree'
|
||||
|
||||
Object.instance_exec do
|
||||
# Undefine SortedSet for two reasons.
|
||||
#
|
||||
# 1. We should wipe out an existing implementation if Ruby 2.x loads
|
||||
# this library after loading the standard set library which
|
||||
# defines SortedSet.
|
||||
#
|
||||
# 2. Ruby >=3.0 (set >=1.0.0) sets autoload on SortedSet, and we
|
||||
# shouldn't let the following reference to SortedSet fire it
|
||||
# because it would end up requiring this library, leading to
|
||||
# circular require.
|
||||
#
|
||||
remove_const :SortedSet if const_defined?(:SortedSet)
|
||||
end
|
||||
|
||||
##
|
||||
# SortedSet implements a Set whose elements are sorted in ascending
|
||||
# order (according to the return values of their `<=>` methods) when
|
||||
# iterating over them.
|
||||
#
|
||||
# Every element in SortedSet must be *mutually comparable* to every
|
||||
# other: comparison with `<=>` must not return nil for any pair of
|
||||
# elements. Otherwise ArgumentError will be raised.
|
||||
#
|
||||
# ## Example
|
||||
#
|
||||
# ```ruby
|
||||
# require "sorted_set"
|
||||
#
|
||||
# set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
|
||||
# ary = []
|
||||
#
|
||||
# set.each do |obj|
|
||||
# ary << obj
|
||||
# end
|
||||
#
|
||||
# p ary # => [1, 2, 3, 4, 5, 6]
|
||||
#
|
||||
# set2 = SortedSet.new([1, 2, "3"])
|
||||
# set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
|
||||
# ```
|
||||
|
||||
class SortedSet < Set
|
||||
# Creates a SortedSet. See Set.new for details.
|
||||
def initialize(*args)
|
||||
@hash = RBTree.new
|
||||
super
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "sorted_set"
|
||||
spec.version = "1.0.3"
|
||||
spec.authors = ["Akinori MUSHA"]
|
||||
spec.email = ["knu@idaemons.org"]
|
||||
|
||||
spec.summary = %q{Implements a variant of Set whose elements are sorted in ascending order}
|
||||
spec.description = %q{Implements a variant of Set whose elements are sorted in ascending order}
|
||||
spec.homepage = "https://github.com/knu/sorted_set"
|
||||
spec.license = "BSD-2-Clause"
|
||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
||||
|
||||
spec.metadata["homepage_uri"] = spec.homepage
|
||||
spec.metadata["source_code_uri"] = spec.homepage
|
||||
spec.metadata["changelog_uri"] = "https://github.com/knu/sorted_set/blob/v#{spec.version}/CHANGELOG.md"
|
||||
|
||||
# Specify which files should be added to the gem when it is released.
|
||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
||||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
end
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
if defined?(JRUBY_VERSION)
|
||||
spec.platform = "java"
|
||||
else
|
||||
spec.add_runtime_dependency "set", "~> 1.0"
|
||||
spec.add_runtime_dependency "rbtree"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user