hashery 2.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8459bb831f3ff14d0b44ff30648c5c6e569de75d
4
- data.tar.gz: 55fae7249dd499b25808e4a4e523f2c01057d55e
2
+ SHA256:
3
+ metadata.gz: 15088e45c4e270297f602666aa98fc94820a86b8625e313620826896f3568d94
4
+ data.tar.gz: '09ec7ae967d0652a909aed5425b362002e983e9e0680bd76883128e7e81d32d4'
5
5
  SHA512:
6
- metadata.gz: 9b2fdfded7c965ef34498e94fd0a47bb2aad42255857c754d985bdcc5ebc4e8d440bf5b0faa9f9edd72918eb53bdfa319e5e22ab4f616ec15c20833e284a7775
7
- data.tar.gz: c175b2f9590ae9c1e608c556132c3f574d12ac842548823786d8003f7a7d55b83a6845f5c74abc18bd3d620f51a04b595f1687af080952e3405ace2c7e42c73f
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,14 +1,12 @@
1
1
  # Hashery
2
2
 
3
- [Homepage](http://rubyworks.github.com/hashery) ·
4
- [Development](http://github.com/rubyworks/hashery) ·
5
- [Report Issue](http://github.com/rubyworks/hashery/issues] ·
6
- [Mailing List](http://googlegroups.com/group.rubyworks-mailinglist] ·
7
- [IRC](irc://irc.freenode.net/rubyworks)
3
+ [![Gem Version](https://img.shields.io/gem/v/hashery.svg?style=flat)](https://rubygems.org/gems/hashery)
4
+ [![CI](https://github.com/rubyworks/hashery/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/hashery/actions/workflows/ci.yml)
5
+ [![Report Issue](https://img.shields.io/github/issues/rubyworks/hashery.svg?style=flat)](https://github.com/rubyworks/hashery/issues)
8
6
 
9
- [![Gem Version](https://badge.fury.io/rb/hashery.png)](http://badge.fury.io/rb/hashery)
10
- [![Build Status](https://secure.travis-ci.org/rubyworks/hashery.png)](http://travis-ci.org/rubyworks/hashery)    
11
- [![Flattr Me](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
7
+ [Homepage](https://rubyworks.github.io/hashery) ·
8
+ [Development](https://github.com/rubyworks/hashery) ·
9
+ [Report Issue](https://github.com/rubyworks/hashery/issues)
12
10
 
13
11
 
14
12
  ## Description
@@ -16,13 +14,12 @@
16
14
  Among Ruby Facets most common additions were an assortment
17
15
  of Hash-like classes. To better support this collection
18
16
  of libraries it was deemed prudent to create a new project
19
- specifically for them. Hence the *Facets* Hashery.
17
+ specifically for them. Hence the *Facets Hashery*.
20
18
 
21
- Included in this collection are the widely used OrderedHash,
22
- the related but more featured Dictionary class, a number
23
- of _open_ classes similar to the standard OpenStruct,
24
- some variations of the standard Hash class and a few
25
- 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.
26
23
 
27
24
 
28
25
  ## Usage
@@ -32,7 +29,37 @@ included in this collection and read the demo documents which give
32
29
  examples of almost all features.
33
30
 
34
31
 
35
- ## Core Extensions
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
+
62
+ ### Core Extensions
36
63
 
37
64
  Hashery adds four core extensions of Ruby's Hash class: `#retrieve`,
38
65
  `#rekey`, `#rekey!` and `Hash.create`. The first is simply an alias
@@ -44,12 +71,14 @@ sorely missing for Ruby itself, which is why they are provided here.
44
71
 
45
72
  ## Installation
46
73
 
47
- To install with RubyGems simply open a console and type:
74
+ Hashery requires Ruby 2.7 or newer. To install with RubyGems simply
75
+ open a console and type:
76
+
77
+ $ gem install hashery
48
78
 
49
- $ sudo gem install hashery
79
+ Or add it as a dependency to your project's Gemfile:
50
80
 
51
- Tarball packages are available for manual site installations
52
- via [Ruby Setup](http://proutils.github.com/setup).
81
+ gem "hashery"
53
82
 
54
83
 
55
84
  ## Authors
@@ -68,37 +97,38 @@ Developers who have contributed code to the project include:
68
97
  ## Contributing
69
98
 
70
99
  Don't be a lump on a log. See an issue? Have a suggestion? Want to help?
71
- Well git in there!
100
+ Well *git* in there!
101
+
102
+ ### Communicating
103
+
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.
72
106
 
73
107
  ### Testing
74
108
 
75
- Hashery uses [QED](http://rubyworks.github.com/qed) and
76
- [Lemon](http://rubyworks.github.com/lemon) test frameworks.
109
+ Hashery uses [QED](https://rubyworks.github.io/qed) and
110
+ [Lemon](https://rubyworks.github.io/lemon) test frameworks.
77
111
  The QED framework to create well tested high-level documentation.
78
- Run the QED specs via:
112
+ Lemon is used to create low-level unit tests. Install the development
113
+ dependencies and run both via:
79
114
 
80
- $ qed -Ilib demo/
115
+ $ bundle install
116
+ $ bundle exec rake
81
117
 
82
- Lemon is used to create low-level unit tests. Run these via the
83
- RubyTest universal test harness.
118
+ Or run the QED specs on their own via:
84
119
 
85
- $ rubytest -Ilib test/
120
+ $ bundle exec qed -Ilib demo/
86
121
 
122
+ And the Lemon unit tests via Rubytest:
123
+
124
+ $ bundle exec rubytest -Ilib -Itest test/
87
125
 
88
126
  ### Patches
89
127
 
90
- Hashery's repository is hosted on [GitHub](http://github.com/rubyworks/hashery).
128
+ Hashery's repository is hosted on [GitHub](https://github.com/rubyworks/hashery).
91
129
  If you'd like to offer up a fix or feature, fork the repo and submit a pull
92
130
  request (preferably in a topic branch). I assume you have heard
93
- all the talk about proper [practices](http://learn.github.com/p/intro.html),
94
- so I won't bug you with it yet again.
95
-
96
- ### Donations
97
-
98
- Yes, we FOSS programmers need to eat too! ;-) No seriously, any help you can
99
- offer goes a long way toward continued development of Rubyworks projects,
100
- including Hashery. See the upper right-hand corner on the
101
- [Rubyworks](http://rubyworks.github.com) homepage. Thanks.
131
+ all the talk about proper practices, so I won't bug you with it yet again.
102
132
 
103
133
 
104
134
  ## Copyrights
@@ -107,7 +137,7 @@ Copyright (c) 2010 Rubyworks
107
137
 
108
138
  Licensed under the *BSD-2-Clause* license.
109
139
 
110
- See COPYING.md file for further details.
140
+ See LICENSE.txt file for further details.
111
141
 
112
142
  Some libraries included in the Hashery have special copyrights
113
143
  attributing specific authors. Please see each library script for
@@ -0,0 +1 @@
1
+ require 'hashery/casting_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/fuzzy_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/key_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/linked_list'
@@ -0,0 +1 @@
1
+ require 'hashery/lru_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/open_cascade'
@@ -0,0 +1 @@
1
+ require 'hashery/open_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/ordered_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/property_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/query_hash'
@@ -0,0 +1 @@
1
+ require 'hashery/static_hash'
@@ -9,7 +9,7 @@ class Hash
9
9
  # Returns a `Hash`.
10
10
  #
11
11
  def self.create(initial_hash={}, &block)
12
- o = new &block
12
+ o = new(&block)
13
13
  o.update(initial_hash)
14
14
  o
15
15
  end
@@ -324,7 +324,7 @@ module Hashery
324
324
  #
325
325
  def replace(other)
326
326
  super cast(other)
327
- end
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 *keys.map{ |key| cast_key(key) }
337
+ super(*keys.map{ |key| cast_key(key) })
338
338
  end
339
339
 
340
340
  # Convert CRUDHash to regular Hash.
@@ -177,7 +177,7 @@ module Hashery
177
177
  unless @fuzz_test
178
178
  @fuzz_test = Object.new
179
179
  @fuzz_test.instance_variable_set(:'@fuzzies', fuzzies)
180
- method = "
180
+ method = +"
181
181
  def match(str)
182
182
  case str\n
183
183
  "
@@ -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.each do |line|
292
+ comment.each_line do |line|
293
293
  file << "# #{line}"
294
294
  end
295
295
  end
@@ -216,7 +216,7 @@ module Hashery
216
216
  #
217
217
  def node_delete(n)
218
218
  node_join(n.prev_node,n.next_node)
219
- v = n.value
219
+ n.value
220
220
  end
221
221
 
222
222
  #