diverse_shuffle 0.1.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 +7 -0
- data/CHANGELOG.md +6 -0
- data/Cargo.lock +281 -0
- data/Cargo.toml +7 -0
- data/LICENSE +21 -0
- data/README.md +91 -0
- data/ext/diverse_shuffle/Cargo.toml +18 -0
- data/ext/diverse_shuffle/extconf.rb +13 -0
- data/ext/diverse_shuffle/src/engine.rs +560 -0
- data/ext/diverse_shuffle/src/lib.rs +9 -0
- data/ext/diverse_shuffle/src/ruby.rs +79 -0
- data/lib/diverse_shuffle/pool.rb +149 -0
- data/lib/diverse_shuffle/rng.rb +48 -0
- data/lib/diverse_shuffle/ruby_engine.rb +262 -0
- data/lib/diverse_shuffle/version.rb +7 -0
- data/lib/diverse_shuffle.rb +86 -0
- metadata +76 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e5ef59cd1a62ac4525a51166c90874da59c6a4b01f8abe594c9f9bd112bd08fd
|
|
4
|
+
data.tar.gz: b946363ea05cbf28f494bce18015a21530acc998ec79488c576ee62f62244aa3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 73b21db620d208b167642a96049d9029a6b3c5709603f2ab8ce9c9ce13c85512e49e6407acd1a22314eb6703cfe8472d5bc0aeb4f56c9899945ad66dcdcb4bee
|
|
7
|
+
data.tar.gz: 82679b54450817e472390a49e6abc37dcb4464d4e5b4203bc0df5ceef39ec66bf737d47d861a0a9bc42732cf942f95d696d71fe40fcafc9f232f2d3537e51fd5
|
data/CHANGELOG.md
ADDED
data/Cargo.lock
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "aho-corasick"
|
|
7
|
+
version = "1.1.5"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"memchr",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "bindgen"
|
|
16
|
+
version = "0.72.1"
|
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
+
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"bitflags",
|
|
21
|
+
"cexpr",
|
|
22
|
+
"clang-sys",
|
|
23
|
+
"itertools",
|
|
24
|
+
"proc-macro2",
|
|
25
|
+
"quote",
|
|
26
|
+
"regex",
|
|
27
|
+
"rustc-hash",
|
|
28
|
+
"shlex",
|
|
29
|
+
"syn",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "bitflags"
|
|
34
|
+
version = "2.13.2"
|
|
35
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
+
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "cexpr"
|
|
40
|
+
version = "0.6.0"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
43
|
+
dependencies = [
|
|
44
|
+
"nom",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[[package]]
|
|
48
|
+
name = "cfg-if"
|
|
49
|
+
version = "1.0.5"
|
|
50
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
51
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
52
|
+
|
|
53
|
+
[[package]]
|
|
54
|
+
name = "clang-sys"
|
|
55
|
+
version = "1.9.1"
|
|
56
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
+
checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
|
|
58
|
+
dependencies = [
|
|
59
|
+
"glob",
|
|
60
|
+
"libc",
|
|
61
|
+
"libloading",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "diverse_shuffle"
|
|
66
|
+
version = "0.1.0"
|
|
67
|
+
dependencies = [
|
|
68
|
+
"magnus",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[[package]]
|
|
72
|
+
name = "either"
|
|
73
|
+
version = "1.19.0"
|
|
74
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
75
|
+
checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
|
76
|
+
|
|
77
|
+
[[package]]
|
|
78
|
+
name = "glob"
|
|
79
|
+
version = "0.3.4"
|
|
80
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
81
|
+
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
|
82
|
+
|
|
83
|
+
[[package]]
|
|
84
|
+
name = "itertools"
|
|
85
|
+
version = "0.13.0"
|
|
86
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
+
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"either",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
[[package]]
|
|
93
|
+
name = "lazy_static"
|
|
94
|
+
version = "1.5.1"
|
|
95
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
96
|
+
checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
|
|
97
|
+
|
|
98
|
+
[[package]]
|
|
99
|
+
name = "libc"
|
|
100
|
+
version = "0.2.191"
|
|
101
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
102
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
103
|
+
|
|
104
|
+
[[package]]
|
|
105
|
+
name = "libloading"
|
|
106
|
+
version = "0.8.9"
|
|
107
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
108
|
+
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
109
|
+
dependencies = [
|
|
110
|
+
"cfg-if",
|
|
111
|
+
"windows-link",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
[[package]]
|
|
115
|
+
name = "magnus"
|
|
116
|
+
version = "0.8.5"
|
|
117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
118
|
+
checksum = "8137349730ade4d395b6cfb3fca073f09d6fdc35b276af17f5b974c44ccc3a21"
|
|
119
|
+
dependencies = [
|
|
120
|
+
"magnus-macros",
|
|
121
|
+
"rb-sys",
|
|
122
|
+
"rb-sys-env",
|
|
123
|
+
"seq-macro",
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
[[package]]
|
|
127
|
+
name = "magnus-macros"
|
|
128
|
+
version = "0.8.0"
|
|
129
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
130
|
+
checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
|
|
131
|
+
dependencies = [
|
|
132
|
+
"proc-macro2",
|
|
133
|
+
"quote",
|
|
134
|
+
"syn",
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
[[package]]
|
|
138
|
+
name = "memchr"
|
|
139
|
+
version = "2.8.3"
|
|
140
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
141
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
142
|
+
|
|
143
|
+
[[package]]
|
|
144
|
+
name = "minimal-lexical"
|
|
145
|
+
version = "0.2.1"
|
|
146
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
147
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
148
|
+
|
|
149
|
+
[[package]]
|
|
150
|
+
name = "nom"
|
|
151
|
+
version = "7.1.3"
|
|
152
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
153
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
|
154
|
+
dependencies = [
|
|
155
|
+
"memchr",
|
|
156
|
+
"minimal-lexical",
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
[[package]]
|
|
160
|
+
name = "proc-macro2"
|
|
161
|
+
version = "1.0.107"
|
|
162
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
163
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
164
|
+
dependencies = [
|
|
165
|
+
"unicode-ident",
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
[[package]]
|
|
169
|
+
name = "quote"
|
|
170
|
+
version = "1.0.47"
|
|
171
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
172
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
173
|
+
dependencies = [
|
|
174
|
+
"proc-macro2",
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
[[package]]
|
|
178
|
+
name = "rb-sys"
|
|
179
|
+
version = "0.9.130"
|
|
180
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
181
|
+
checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
|
|
182
|
+
dependencies = [
|
|
183
|
+
"rb-sys-build",
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
[[package]]
|
|
187
|
+
name = "rb-sys-build"
|
|
188
|
+
version = "0.9.130"
|
|
189
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
+
checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
|
|
191
|
+
dependencies = [
|
|
192
|
+
"bindgen",
|
|
193
|
+
"lazy_static",
|
|
194
|
+
"proc-macro2",
|
|
195
|
+
"quote",
|
|
196
|
+
"regex",
|
|
197
|
+
"shell-words",
|
|
198
|
+
"syn",
|
|
199
|
+
]
|
|
200
|
+
|
|
201
|
+
[[package]]
|
|
202
|
+
name = "rb-sys-env"
|
|
203
|
+
version = "0.2.3"
|
|
204
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
205
|
+
checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
|
|
206
|
+
|
|
207
|
+
[[package]]
|
|
208
|
+
name = "regex"
|
|
209
|
+
version = "1.13.2"
|
|
210
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
211
|
+
checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
|
|
212
|
+
dependencies = [
|
|
213
|
+
"aho-corasick",
|
|
214
|
+
"memchr",
|
|
215
|
+
"regex-automata",
|
|
216
|
+
"regex-syntax",
|
|
217
|
+
]
|
|
218
|
+
|
|
219
|
+
[[package]]
|
|
220
|
+
name = "regex-automata"
|
|
221
|
+
version = "0.4.19"
|
|
222
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
223
|
+
checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
|
|
224
|
+
dependencies = [
|
|
225
|
+
"aho-corasick",
|
|
226
|
+
"memchr",
|
|
227
|
+
"regex-syntax",
|
|
228
|
+
]
|
|
229
|
+
|
|
230
|
+
[[package]]
|
|
231
|
+
name = "regex-syntax"
|
|
232
|
+
version = "0.8.12"
|
|
233
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
234
|
+
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
|
235
|
+
|
|
236
|
+
[[package]]
|
|
237
|
+
name = "rustc-hash"
|
|
238
|
+
version = "2.1.3"
|
|
239
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
240
|
+
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
|
241
|
+
|
|
242
|
+
[[package]]
|
|
243
|
+
name = "seq-macro"
|
|
244
|
+
version = "0.3.6"
|
|
245
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
246
|
+
checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
|
|
247
|
+
|
|
248
|
+
[[package]]
|
|
249
|
+
name = "shell-words"
|
|
250
|
+
version = "1.1.1"
|
|
251
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
252
|
+
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
|
|
253
|
+
|
|
254
|
+
[[package]]
|
|
255
|
+
name = "shlex"
|
|
256
|
+
version = "1.3.0"
|
|
257
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
258
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
259
|
+
|
|
260
|
+
[[package]]
|
|
261
|
+
name = "syn"
|
|
262
|
+
version = "2.0.119"
|
|
263
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
264
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
265
|
+
dependencies = [
|
|
266
|
+
"proc-macro2",
|
|
267
|
+
"quote",
|
|
268
|
+
"unicode-ident",
|
|
269
|
+
]
|
|
270
|
+
|
|
271
|
+
[[package]]
|
|
272
|
+
name = "unicode-ident"
|
|
273
|
+
version = "1.0.27"
|
|
274
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
275
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
276
|
+
|
|
277
|
+
[[package]]
|
|
278
|
+
name = "windows-link"
|
|
279
|
+
version = "0.2.1"
|
|
280
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
281
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
data/Cargo.toml
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Love Wins Media, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# diverse_shuffle
|
|
2
|
+
|
|
3
|
+
A seeded shuffle where neighbouring songs aren't too alike. You give it songs, how far apart pairs of tracks are
|
|
4
|
+
(cosine distances from your vector store, say) and which attributes they share (voice, era, show), plus hard rules
|
|
5
|
+
over those: how far a song must be from the songs just before it, how many of the window may share an attribute,
|
|
6
|
+
how many songs must pass before an attribute comes back. It places every song, in an order that's the same for the
|
|
7
|
+
same seed.
|
|
8
|
+
|
|
9
|
+
The work runs in Rust (a native extension, precompiled for Linux and macOS on x86_64 and ARM). Where it isn't built,
|
|
10
|
+
a pure-Ruby engine places the songs instead, with exactly the same result: the specs hold the two engines to each
|
|
11
|
+
other on random pools, mode by mode, and every float is worked out in the same order on both sides.
|
|
12
|
+
|
|
13
|
+
On a 500-song pool with six rules, the Rust engine places every song in about 40 to 55 ms; the Ruby engine takes
|
|
14
|
+
about 1.1 s.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'diverse_shuffle'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require 'diverse_shuffle'
|
|
26
|
+
E = DiverseShuffle::Engine
|
|
27
|
+
|
|
28
|
+
# Three tracks; four songs (two play the same track, one is a song nothing is known about).
|
|
29
|
+
sound = E::VectorRule.new(weight: 1.0, min_distance: 0.25, pairs: [[0, 1, 0.42], [0, 2, 0.07], [1, 2, 0.6]])
|
|
30
|
+
# Per track, one list of value ids per key (here one key, the show), or nil for a track with no attributes.
|
|
31
|
+
show = E::MatchRule.new(weight: 0.5, min_gap: 2, values: [[[7]], [[7]], [[3]]])
|
|
32
|
+
pool = E::Pool.new(songs: [0, 1, 2, nil], tracks: 3, rules: [sound, show])
|
|
33
|
+
|
|
34
|
+
E.place(pool, seed: 'tuesday', mode: :mmr)
|
|
35
|
+
# => [#<data DiverseShuffle::Engine::Placement song=1, level=0, considered=4, rejected=0>, ...]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`song` is an index into `pool.songs`; `level` is how far the rules had to loosen for the song to pass (0 when they
|
|
39
|
+
didn't); `considered` and `rejected` say how many songs were looked at for the slot and how many were ruled out.
|
|
40
|
+
|
|
41
|
+
### Modes
|
|
42
|
+
|
|
43
|
+
- `:greedy` takes, for each slot, the first song in shuffled order that passes every hard rule.
|
|
44
|
+
- `:mmr` takes the best of the first `mmr_k` passing songs by soft score (how far the song sits from the window
|
|
45
|
+
before it, weighted per rule), plus up to `mmr_jitter` of randomness.
|
|
46
|
+
- `:dpp` picks spread-out sets of `dpp_batch` songs (greedy MAP inference for a determinantal point process, with
|
|
47
|
+
incremental Cholesky), then places each set with the greedy rules.
|
|
48
|
+
|
|
49
|
+
### Rules
|
|
50
|
+
|
|
51
|
+
- `VectorRule.new(weight:, pairs:, min_distance: nil)`: `pairs` are `[track, track, distance]`. A song must be at
|
|
52
|
+
least `min_distance` from the songs it's compared with. A pair with no distance is unknown and never rules a song
|
|
53
|
+
out.
|
|
54
|
+
- `MatchRule.new(weight:, values:, max_same_in_window: nil, min_gap: nil)`: two songs are the same when they share a
|
|
55
|
+
value on every key. Fewer than `max_same_in_window` songs of the window may be the same, and none of the last
|
|
56
|
+
`min_gap`.
|
|
57
|
+
|
|
58
|
+
### Settings
|
|
59
|
+
|
|
60
|
+
`E::Settings.new(window: 3, compare: :window, loosen_steps: 3, loosen_factor: 0.75, mmr_k: 8, mmr_jitter: 0.15,
|
|
61
|
+
dpp_batch: 8)`, passed as `settings:`.
|
|
62
|
+
|
|
63
|
+
- `window`: how many songs back the hard rules and the soft score look.
|
|
64
|
+
- `compare`: `:window` compares distances against every song in the window, `:previous` against the one before
|
|
65
|
+
only.
|
|
66
|
+
- `loosen_steps`, `loosen_factor`: when no song passes, the rules loosen a step at a time (distances times
|
|
67
|
+
`loosen_factor` per step, one more same song allowed in the window, the gap one shorter); past the last step every
|
|
68
|
+
song passes, so it never stalls.
|
|
69
|
+
|
|
70
|
+
### Engines
|
|
71
|
+
|
|
72
|
+
`DiverseShuffle::Engine.engine` says which engine `place` uses: `:native` where the extension is loaded, else
|
|
73
|
+
`:ruby`. Set `DIVERSE_SHUFFLE_ENGINE=ruby` to use Ruby anyway, or pass `engine: :ruby`.
|
|
74
|
+
|
|
75
|
+
## Develop
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
bundle install
|
|
79
|
+
bundle exec rake compile # builds the Rust extension (needs a Rust toolchain)
|
|
80
|
+
bundle exec rspec # specs, including the Rust engine against the Ruby one
|
|
81
|
+
cargo test --manifest-path ext/diverse_shuffle/Cargo.toml --no-default-features
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Release
|
|
85
|
+
|
|
86
|
+
Bump `DiverseShuffle::Engine::VERSION`, add a CHANGELOG entry, merge to main and run the Release workflow (or push
|
|
87
|
+
a `vX.Y.Z` tag). It builds the platform gems and the source gem and publishes them with RubyGems trusted publishing.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT. Made by Love Wins Media, Inc.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "diverse_shuffle"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
publish = false
|
|
7
|
+
rust-version = "1.85"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
crate-type = ["cdylib", "rlib"]
|
|
11
|
+
|
|
12
|
+
[features]
|
|
13
|
+
# The Ruby glue. `cargo test --no-default-features` tests the engine alone, with nothing to link against Ruby.
|
|
14
|
+
default = ["ruby"]
|
|
15
|
+
ruby = ["dep:magnus"]
|
|
16
|
+
|
|
17
|
+
[dependencies]
|
|
18
|
+
magnus = { version = "0.8", optional = true }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mkmf'
|
|
4
|
+
|
|
5
|
+
# Without a Rust toolchain the extension isn't built and the Ruby engine places songs instead (same results, slower):
|
|
6
|
+
# the install still succeeds. The platform gems are precompiled, so this only matters for the source gem.
|
|
7
|
+
if find_executable('cargo')
|
|
8
|
+
require 'rb_sys/mkmf'
|
|
9
|
+
create_rust_makefile('diverse_shuffle/diverse_shuffle')
|
|
10
|
+
else
|
|
11
|
+
warn 'diverse_shuffle: no Rust toolchain (cargo) found, so the Rust engine is not built; using the Ruby engine.'
|
|
12
|
+
File.write('Makefile', "all install clean:\n\t@:\n.PHONY: all install clean\n")
|
|
13
|
+
end
|