hashery 2.1.2 → 2.2.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.
- checksums.yaml +5 -5
- data/HISTORY.md +37 -0
- data/README.md +59 -42
- data/lib/hashery/core_ext.rb +1 -1
- data/lib/hashery/crud_hash.rb +2 -2
- data/lib/hashery/fuzzy_hash.rb +1 -1
- data/lib/hashery/ini_hash.rb +4 -4
- data/lib/hashery/linked_list.rb +1 -1
- data/lib/hashery/lru_hash.rb +167 -160
- data/lib/hashery/open_hash.rb +2 -2
- data/lib/hashery/static_hash.rb +2 -0
- data/lib/hashery/version.rb +3 -0
- data/lib/hashery.rb +1 -3
- data/test/case_association.rb +2 -2
- data/test/case_ini_hash.rb +24 -0
- data/test/case_lru_hash.rb +276 -6
- metadata +15 -72
- data/.index +0 -78
- data/Index.yml +0 -52
- data/lib/hashery.yml +0 -78
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 15088e45c4e270297f602666aa98fc94820a86b8625e313620826896f3568d94
|
|
4
|
+
data.tar.gz: '09ec7ae967d0652a909aed5425b362002e983e9e0680bd76883128e7e81d32d4'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd8bf0d32c1c5b8c301beda12612679bae8d3e76a7ede77a70a9a6984d8b4096cb766076e8814d85ae819686b1b6807d89a5027c29bbcd7e2eac80f4a9b802f0
|
|
7
|
+
data.tar.gz: e6ffe274fb89be2e26e9a21e715d118ec795d3c4bcc4bad82218c5c2cebb8f6c677b645fa07a3ac37a9171e24471d996eb26213469ce5d77b5a2938451227184
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# RELEASE HISTORY
|
|
2
2
|
|
|
3
|
+
## 2.2.0 / 2026-11-16
|
|
4
|
+
|
|
5
|
+
This release concentrates on LRUHash, by far the most used part of the
|
|
6
|
+
Hashery. Its public API is unchanged, but it has been reimplemented on top
|
|
7
|
+
of Ruby's ordered Hash instead of a linked list of nodes, which makes it
|
|
8
|
+
about twice as fast, and a number of bugs have been fixed. It also
|
|
9
|
+
modernizes the project: Ruby 2.7 or newer is now required, the gem is
|
|
10
|
+
built from a plain gemspec, and CI runs on GitHub Actions.
|
|
11
|
+
|
|
12
|
+
Changes:
|
|
13
|
+
|
|
14
|
+
* LRUHash is about 2x faster, using Ruby's ordered Hash internally.
|
|
15
|
+
* Fix LRUHash#dup and #clone, which shared state with the original.
|
|
16
|
+
* Fix LRUHash#inspect and #to_s, which showed keys and values with #to_s
|
|
17
|
+
and failed under frozen string literals.
|
|
18
|
+
* LRUHash#keys and #values now list most recently used first, like #each.
|
|
19
|
+
* LRUHash#fetch accepts a default argument and its KeyError names the key.
|
|
20
|
+
* LRUHash#delete accepts a block for missing keys, like Hash#delete.
|
|
21
|
+
* LRUHash#delete_if returns an Enumerator when called without a block.
|
|
22
|
+
* Add LRUHash#length.
|
|
23
|
+
* Fix IniHash.new with a Hash, and so IniHash.text and .write_to_file.
|
|
24
|
+
* Fix IniHash.write_to_file with a comment (used String#each).
|
|
25
|
+
* Fix `require 'hashery/static_hash'` on its own.
|
|
26
|
+
* Prepare for frozen string literals and fix warnings under `ruby -w`.
|
|
27
|
+
* Require Ruby 2.7 or newer.
|
|
28
|
+
* Replace Indexer metadata (.index, Index.yml) with hashery.gemspec.
|
|
29
|
+
* Replace Travis CI with GitHub Actions.
|
|
30
|
+
|
|
31
|
+
## 2.1.2 / 2016-05-02
|
|
32
|
+
|
|
33
|
+
Minor release fixes a test for KeyHash. And that's it.
|
|
34
|
+
|
|
35
|
+
Changes:
|
|
36
|
+
|
|
37
|
+
* Fix initialize test for KeyHash class.
|
|
38
|
+
|
|
39
|
+
|
|
3
40
|
## 2.1.1 / 2013-08-21
|
|
4
41
|
|
|
5
42
|
This minor release clarifies the licensing. The entire library is now
|
data/README.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
# Hashery
|
|
2
2
|
|
|
3
|
-
[](http://github.com/rubyworks/hashery/issues)
|
|
7
|
-
[](https://www.gittip.com/rubyworksorg/)
|
|
3
|
+
[](https://rubygems.org/gems/hashery)
|
|
4
|
+
[](https://github.com/rubyworks/hashery/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/rubyworks/hashery/issues)
|
|
8
6
|
|
|
9
|
-
[Homepage](
|
|
10
|
-
[Development](
|
|
11
|
-
[Report Issue](
|
|
12
|
-
[Chat](https://kiwiirc.com/client/irc.freenode.net/?nick=user1|?#rubyworks)
|
|
7
|
+
[Homepage](https://rubyworks.github.io/hashery) ·
|
|
8
|
+
[Development](https://github.com/rubyworks/hashery) ·
|
|
9
|
+
[Report Issue](https://github.com/rubyworks/hashery/issues)
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
## Description
|
|
@@ -19,11 +16,10 @@ of Hash-like classes. To better support this collection
|
|
|
19
16
|
of libraries it was deemed prudent to create a new project
|
|
20
17
|
specifically for them. Hence the *Facets Hashery*.
|
|
21
18
|
|
|
22
|
-
Included in this collection are the widely used
|
|
23
|
-
the
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
other yummy morsels.
|
|
19
|
+
Included in this collection are the widely used LRUHash,
|
|
20
|
+
the auto-sorting Dictionary class, a number of _open_ classes
|
|
21
|
+
similar to the standard OpenStruct, some variations of the
|
|
22
|
+
standard Hash class and a few other yummy morsels.
|
|
27
23
|
|
|
28
24
|
|
|
29
25
|
## Usage
|
|
@@ -33,6 +29,36 @@ included in this collection and read the demo documents which give
|
|
|
33
29
|
examples of almost all features.
|
|
34
30
|
|
|
35
31
|
|
|
32
|
+
### LRUHash
|
|
33
|
+
|
|
34
|
+
`Hashery::LRUHash` is a size-limited Hash that evicts the least recently
|
|
35
|
+
used entry when full. It can be required on its own:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
require 'hashery/lru_hash'
|
|
39
|
+
|
|
40
|
+
cache = Hashery::LRUHash.new(2)
|
|
41
|
+
cache[:a] = 1
|
|
42
|
+
cache[:b] = 2
|
|
43
|
+
cache[:a] # reading :a makes it the most recently used
|
|
44
|
+
cache[:c] = 3 # full, so :b, the least recently used, is evicted
|
|
45
|
+
|
|
46
|
+
cache.keys # => [:c, :a] (most recently used first)
|
|
47
|
+
cache.fetch(:b, 0) # => 0
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Reading with `#[]`, `#fetch`, `#assoc`, `#rassoc`, `#key` or `#values_at`
|
|
51
|
+
marks an entry as most recently used; `#has_key?`, `#has_value?` and iteration
|
|
52
|
+
do not. Like `Hash.new`, it takes an optional default value or block. Set
|
|
53
|
+
`#release_proc` to be told about every entry that leaves the cache:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
cache.release_proc = ->(key, value) { value.close }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
An LRUHash is not thread-safe; guard it with a `Mutex` if threads share it.
|
|
60
|
+
|
|
61
|
+
|
|
36
62
|
### Core Extensions
|
|
37
63
|
|
|
38
64
|
Hashery adds four core extensions of Ruby's Hash class: `#retrieve`,
|
|
@@ -45,17 +71,15 @@ sorely missing for Ruby itself, which is why they are provided here.
|
|
|
45
71
|
|
|
46
72
|
## Installation
|
|
47
73
|
|
|
48
|
-
To install with RubyGems simply
|
|
74
|
+
Hashery requires Ruby 2.7 or newer. To install with RubyGems simply
|
|
75
|
+
open a console and type:
|
|
49
76
|
|
|
50
|
-
$
|
|
77
|
+
$ gem install hashery
|
|
51
78
|
|
|
52
79
|
Or add it as a dependency to your project's Gemfile:
|
|
53
80
|
|
|
54
81
|
gem "hashery"
|
|
55
82
|
|
|
56
|
-
Tarball packages are available for manual site installations
|
|
57
|
-
via [Ruby Setup](http://rubyworks.github.com/setup).
|
|
58
|
-
|
|
59
83
|
|
|
60
84
|
## Authors
|
|
61
85
|
|
|
@@ -77,41 +101,34 @@ Well *git* in there!
|
|
|
77
101
|
|
|
78
102
|
### Communicating
|
|
79
103
|
|
|
80
|
-
The project is hosted on
|
|
81
|
-
is via the [Issues](
|
|
82
|
-
For more direct communication you can try the **#rubyworks** IRC channel
|
|
83
|
-
on **irc.freenode.net**.
|
|
84
|
-
|
|
85
|
-
[](https://kiwiirc.com/client/irc.freenode.net/?nick=user1|?#rubyworks)
|
|
104
|
+
The project is hosted on GitHub so the easiest means of communication
|
|
105
|
+
is via the [Issues](https://github.com/rubyworks/hashery/issues) page.
|
|
86
106
|
|
|
87
107
|
### Testing
|
|
88
108
|
|
|
89
|
-
Hashery uses [QED](
|
|
90
|
-
[Lemon](
|
|
109
|
+
Hashery uses [QED](https://rubyworks.github.io/qed) and
|
|
110
|
+
[Lemon](https://rubyworks.github.io/lemon) test frameworks.
|
|
91
111
|
The QED framework to create well tested high-level documentation.
|
|
92
|
-
|
|
112
|
+
Lemon is used to create low-level unit tests. Install the development
|
|
113
|
+
dependencies and run both via:
|
|
114
|
+
|
|
115
|
+
$ bundle install
|
|
116
|
+
$ bundle exec rake
|
|
93
117
|
|
|
94
|
-
|
|
118
|
+
Or run the QED specs on their own via:
|
|
95
119
|
|
|
96
|
-
|
|
120
|
+
$ bundle exec qed -Ilib demo/
|
|
97
121
|
|
|
98
|
-
|
|
122
|
+
And the Lemon unit tests via Rubytest:
|
|
123
|
+
|
|
124
|
+
$ bundle exec rubytest -Ilib -Itest test/
|
|
99
125
|
|
|
100
126
|
### Patches
|
|
101
127
|
|
|
102
|
-
Hashery's repository is hosted on [GitHub](
|
|
128
|
+
Hashery's repository is hosted on [GitHub](https://github.com/rubyworks/hashery).
|
|
103
129
|
If you'd like to offer up a fix or feature, fork the repo and submit a pull
|
|
104
130
|
request (preferably in a topic branch). I assume you have heard
|
|
105
|
-
all the talk about proper
|
|
106
|
-
so I won't bug you with it yet again.
|
|
107
|
-
|
|
108
|
-
### Donations
|
|
109
|
-
|
|
110
|
-
Yes, we FOSS programmers need to eat too! ;-) No seriously, any help you can
|
|
111
|
-
offer goes a long way toward continued development of Rubyworks projects,
|
|
112
|
-
including Hashery. Hop over to our [Gittips](https://www.gittip.com/rubyworksorg/)
|
|
113
|
-
page, or see the upper right-hand corner on the [Rubyworks](http://rubyworks.github.com) homepage.
|
|
114
|
-
Thanks!
|
|
131
|
+
all the talk about proper practices, so I won't bug you with it yet again.
|
|
115
132
|
|
|
116
133
|
|
|
117
134
|
## Copyrights
|
data/lib/hashery/core_ext.rb
CHANGED
data/lib/hashery/crud_hash.rb
CHANGED
|
@@ -324,7 +324,7 @@ module Hashery
|
|
|
324
324
|
#
|
|
325
325
|
def replace(other)
|
|
326
326
|
super cast(other)
|
|
327
|
-
|
|
327
|
+
end
|
|
328
328
|
|
|
329
329
|
#
|
|
330
330
|
# Get the values at.
|
|
@@ -334,7 +334,7 @@ module Hashery
|
|
|
334
334
|
# Returns `Array` of values.
|
|
335
335
|
#
|
|
336
336
|
def values_at(*keys)
|
|
337
|
-
super
|
|
337
|
+
super(*keys.map{ |key| cast_key(key) })
|
|
338
338
|
end
|
|
339
339
|
|
|
340
340
|
# Convert CRUDHash to regular Hash.
|
data/lib/hashery/fuzzy_hash.rb
CHANGED
data/lib/hashery/ini_hash.rb
CHANGED
|
@@ -115,7 +115,7 @@ module Hashery
|
|
|
115
115
|
@path = path if String === path
|
|
116
116
|
@inihash = (Hash === path ? path.dup : {})
|
|
117
117
|
|
|
118
|
-
if load or ( load.nil? and FileTest.readable_real? @path )
|
|
118
|
+
if load or ( load.nil? and @path and FileTest.readable_real? @path )
|
|
119
119
|
restore()
|
|
120
120
|
end
|
|
121
121
|
end
|
|
@@ -185,7 +185,7 @@ module Hashery
|
|
|
185
185
|
# Returns a string in the ini file format.
|
|
186
186
|
#
|
|
187
187
|
def to_s
|
|
188
|
-
str = ""
|
|
188
|
+
str = +""
|
|
189
189
|
inihash.each do |key, value|
|
|
190
190
|
if value.is_a? Hash
|
|
191
191
|
str << "[#{key.to_s}]\n"
|
|
@@ -259,7 +259,7 @@ module Hashery
|
|
|
259
259
|
# Returns a `String` with the comments from the beginning of the INI file.
|
|
260
260
|
#
|
|
261
261
|
def self.read_comment_from_file(path)
|
|
262
|
-
comment = ""
|
|
262
|
+
comment = +""
|
|
263
263
|
|
|
264
264
|
IO.foreach(path) do |line|
|
|
265
265
|
line.strip!
|
|
@@ -289,7 +289,7 @@ module Hashery
|
|
|
289
289
|
File.open(path, "w") { |file|
|
|
290
290
|
|
|
291
291
|
unless comment.nil?
|
|
292
|
-
comment.
|
|
292
|
+
comment.each_line do |line|
|
|
293
293
|
file << "# #{line}"
|
|
294
294
|
end
|
|
295
295
|
end
|