ruby-fst 0.2.2-x86_64-linux → 0.3.0-x86_64-linux

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
2
  SHA256:
3
- metadata.gz: a453953e975d4068f96a28eb5a2b29ece5879bc13e556e9c3b08a1a04e25eae3
4
- data.tar.gz: c3a9c1dff5d755c05b567772c5c3045b80485e387b2d2c8e2ebbe4a15d3a5649
3
+ metadata.gz: 28ee0e874ad9f256ba5e1d194a8ce72ac186abe8ba56a43acee13802195fd81c
4
+ data.tar.gz: ad91dd6b2f5b6eac5c45121597ac38ec81b26d0d152a13910cd92e4643955c8a
5
5
  SHA512:
6
- metadata.gz: 256a6906f551033b49b04a4f25fb2ef44699bd2138f34da41f167324e73a0e7c4c687ef6ded252672c396eff315dc914939bf773cf7879b37fb3cf8d39cb9087
7
- data.tar.gz: c1298bde498c8076adb617050b7aac5541459ce7e1462501847baae9d4e3de184bd13950bd0b7b74015cc3d8dd234413fd2d691bb4a98e6a22879709886b81a4
6
+ metadata.gz: f7aefe95d7f4a0825b6358ed93b4c7518ba8957109216b15eab9918880ae971568b1c0ba770188762313883c35c122c48224f710ac99edb0334f896b98634271
7
+ data.tar.gz: 8c1cb7475efae7d86a119f5edbff47e2100e587d77527c223d43d9d64dacbc76f141ae836ec42fc2a0bc6a1604bbedd3d176fb0683b8ee070b6d3d2ef7361b26
data/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.0] — 2026-10-26
10
+
11
+ ### Changed
12
+ - I/O failures now raise `IOError` instead of `RuntimeError`, and Levenshtein queries too large to
13
+ compile raise `ArgumentError`. Other errors raise the new `RubyFst::Error`, a `RuntimeError`
14
+ subclass, so existing `rescue RuntimeError` for builder and format errors keeps working.
15
+ - `new` and `from_path` verify the FST checksum. Corrupt data now raises `RubyFst::Error`; before,
16
+ it could return wrong results or terminate the process. FSTs written by fst < 0.4 have no
17
+ checksum and still load unverified. `from_path_mmap` does not verify.
18
+ - Paths accept `Pathname`, and on Unix non-UTF-8 file names.
19
+ - `each` and `search_levenshtein` return an `Enumerator` when called without a block.
20
+ - In-memory FSTs report their size to Ruby's GC.
21
+
22
+ - `save` writes a temporary file and renames it into place, so readers never see a partial file.
23
+ Symlinks are followed and permissions kept, but the replacement is a new file: hard links to the
24
+ old one are broken and ownership becomes the saving user's. Where a rename can't work (a
25
+ non-regular target such as a FIFO, or an unwritable directory) it writes in place as before. A
26
+ crash mid-save can leave a `<path>.tmp-<pid>` file behind.
27
+
28
+ ### Fixed
29
+ - Saving over a memory-mapped file no longer crashes the process with `SIGBUS` on Linux and macOS.
30
+ Windows can't replace a mapped file, so `save` raises `IOError` there.
31
+
9
32
  ## [0.2.2] — 2026-09-24
10
33
 
11
34
  ### Fixed
data/README.md CHANGED
@@ -25,7 +25,7 @@ gem 'ruby-fst'
25
25
 
26
26
  All FST keys are arbitrary byte strings (`Encoding::BINARY`). When a key is returned from the gem (e.g. via `each`, `get_le`, `range`) it always carries the `Encoding::BINARY` encoding — be careful when interpolating into UTF-8 strings or `puts`-ing keys that contain non-ASCII bytes.
27
27
 
28
- Keys must be inserted into a builder in **strictly ascending lexicographic byte order**, with no duplicates. Out-of-order or duplicate inserts raise.
28
+ Keys must be inserted into a builder in **strictly ascending lexicographic byte order**, with no duplicates. Out-of-order or duplicate inserts raise `RubyFst::Error`.
29
29
 
30
30
  ## Map
31
31
 
@@ -156,7 +156,15 @@ map = RubyFst::Map.from_path('/path/to/file.fst')
156
156
  map = RubyFst::Map.from_path_mmap('/path/to/file.fst')
157
157
  ```
158
158
 
159
- When using `from_path_mmap`, the file must remain unchanged on disk for the lifetime of the resulting `Map` or `Set` — modifying or truncating it causes undefined behavior.
159
+ `new` and `from_path` verify the FST's checksum (FSTs written before fst 0.4 have none and load unverified) and raise `RubyFst::Error` on corrupt or invalid data. `from_path_mmap` skips the check so that opening a large file stays cheap, which means a corrupt file can return wrong results or terminate the process — only memory-map files you trust.
160
+
161
+ When using `from_path_mmap`, the file must remain unchanged on disk for the lifetime of the resulting `Map` or `Set` — modifying or truncating it in place causes undefined behavior. `save` writes to a temporary file beside the target and renames it into place, so on Linux and macOS saving over a mapped file is safe: the existing mapping keeps reading the old contents. Windows refuses to replace a file while it is mapped, so there `save` raises `IOError` instead.
162
+
163
+ ## Errors
164
+
165
+ - `IOError` — a file couldn't be read, mapped, or written.
166
+ - `ArgumentError` — a Levenshtein query too large to build an automaton for.
167
+ - `RubyFst::Error` (a `RuntimeError` subclass) — invalid or corrupt FST data, out-of-order builder inserts, or a builder used after `finish`.
160
168
 
161
169
  ## Development
162
170
 
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyFst
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/ruby_fst.rb CHANGED
@@ -9,6 +9,12 @@ end
9
9
 
10
10
  module RubyFst
11
11
  module RangeQuery
12
+ def each(&block)
13
+ return enum_for(:each) { size } unless block
14
+
15
+ _each(&block)
16
+ end
17
+
12
18
  def range(ge: nil, le: nil, &block)
13
19
  return enum_for(:range, ge:, le:) unless block
14
20
 
@@ -20,14 +26,22 @@ module RubyFst
20
26
 
21
27
  _starts_with(prefix, &block)
22
28
  end
29
+
30
+ def search_levenshtein(query, distance, &block)
31
+ return enum_for(:search_levenshtein, query, distance) unless block
32
+
33
+ _search_levenshtein(query, distance, &block)
34
+ end
23
35
  end
24
36
 
25
37
  class Map
26
38
  include Enumerable
27
39
 
40
+ alias _each each
28
41
  alias _range range
29
42
  alias _starts_with starts_with
30
- private :_range, :_starts_with
43
+ alias _search_levenshtein search_levenshtein
44
+ private :_each, :_range, :_starts_with, :_search_levenshtein
31
45
 
32
46
  prepend RangeQuery
33
47
  end
@@ -35,9 +49,11 @@ module RubyFst
35
49
  class Set
36
50
  include Enumerable
37
51
 
52
+ alias _each each
38
53
  alias _range range
39
54
  alias _starts_with starts_with
40
- private :_range, :_starts_with
55
+ alias _search_levenshtein search_levenshtein
56
+ private :_each, :_range, :_starts_with, :_search_levenshtein
41
57
 
42
58
  prepend RangeQuery
43
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Denis Sablic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-23 00:00:00.000000000 Z
11
+ date: 2026-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Finite state transducer backed ordered sets and maps via the Rust fst
14
14
  crate by BurntSushi