File: README.md

package info (click to toggle)
ruby-sorted-set 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: ruby: 114; makefile: 4; sh: 4
file content (58 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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).