Max Cahill
8a57ae458f
added changes to accept spairs; merged #58
2022-05-23 14:48:52 +10:00
jalhund
199b8ded1d
tablex: Add spairs (alternative of pairs that returns sorted table)
2022-05-18 05:17:55 +00:00
Max Cahill
213ba5df0f
added tablex.copy
is an alias for tablex.shallow_copy
, same for overlay
, bunch of whitespace changes, some additional asserts
2022-03-07 12:00:05 +11:00
Max Cahill
461c3a8131
Merge pull request #52 from idbrii/table-deep-test
...
tablex: Add deep & shallow for copy, overlay; remove redundant recursion; add tests
2022-03-07 10:27:35 +11:00
David Briscoe
d48d4b0e81
table: Rewrite *_copy to copy any kind of type
...
Allowing shallow_copy/deep_copy to accept any type makes it easier to
write generic code where you just want to copy some input without
knowing anything about it. Like an event system, save system, etc.
Add corresponding test.
Tests pass
2022-03-03 22:03:12 -08:00
David Briscoe
9083ee74ca
lint: Fix accessing undefined append_inplace
...
Fix crash when using append_inplace without batteries:export().
If you don't export batteries into the global namespace to stomp table,
then append_inplace would access a nil function because it's using table
instead of tablex.
We still use table inside init, but that's after we export to global
namespace.
2022-03-03 10:17:35 -08:00
David Briscoe
a5ebc1e501
lint: Fix shadow issues
...
Fix shadowing by using variables with a different name or _.
I don't think any of these warnings were actual bugs and fixed them to
maintain the same behaviour.
2022-03-03 10:17:34 -08:00
David Briscoe
5fa80ca97c
tablex: Add deep & shallow for copy, overlay
...
Replace copy with shallow_copy, deep_copy.
Replace overlay with shallow_overlay, deep_overlay.
Significant rewrite of these functions and their semantics to update to
the note above them.
Add corresponding tests.
2022-03-03 10:04:28 -08:00
David Briscoe
5b4d1c16c5
tablex: Skip equality comparison in equal fn
...
The second loop doesn't care if the values are equal. It only checks if
the keys are there. The first loop already checked for equality.
Add tests to prove correctness using testy.lua.
2022-03-03 10:04:28 -08:00
Max Cahill
e731a167d8
added tablex.shallow_equal and tablex.deep_equal, slow functions for content-based (in)equality of different tables
2021-11-23 11:40:31 +11:00
Max Cahill
72cb14b8ec
Merge branch feature/tablex.pick_weighted_random
...
minor changes to error handling and docs
2021-11-23 10:58:56 +11:00
Jesse Viikari
a42f1190e0
Modified weighted random pick function
...
- Now accepts a table from which it will pick the random value from,
instead of an index
- Changed function name to better reflect the way it now works
2021-11-19 10:03:40 +02:00
Max Cahill
31bfe92d37
added todo for tablex.weighted_random, removed returning the weight value as multi-return wasn't documented and could break in some circumstances
2021-11-18 10:35:26 +11:00
Jesse Viikari
7eb6bcc576
Add a weighted random pick for tablex
2021-11-17 20:20:04 +02:00
Max Cahill
63a1cf5438
Merge PR #39 : add ripairs
...
minor: touched up whitespace/naming/comments
2021-11-11 13:47:24 +11:00
Max Cahill
8aa6107056
made tablex relative require consistent with other modules
2021-11-11 13:42:03 +11:00
Westerbly Snaydley
cf8e0ac81a
add ripairs (reverse ipairs)
2021-11-09 23:45:01 -05:00
Max Cahill
27b548bb25
changed tablex.rotate loop bounds to be more defensive about fractional arguments being passed
2021-10-08 10:19:30 +11:00
Max Cahill
0a02d7a2da
Merge feature/tablex.rotate
...
refactored to use loops instead of recursion for simplicity
2021-10-08 10:17:34 +11:00
flamendless
8a069c38d4
[tablex] Add rotate
2021-10-03 17:31:55 +08:00
Max Cahill
0691f2bd36
added tablex.random_index
2021-07-06 08:29:45 +10:00
Max Cahill
1de942daa8
Use luajit table.clear properly
...
Fixes #25
2021-06-29 14:46:40 +10:00
Max Cahill
9b95643e6e
Added tablex.swap_and_pop
2021-06-09 19:49:04 +10:00
DUznanski
2846de2ea3
Fix shuffle to avoid bias
...
There's a subtle trick in shuffling: you should draw only from the part of the deck you have not seen! Otherwise, some permutations are more common than others.
2021-05-20 12:33:52 -07:00
Max Cahill
a397d3d7f8
Merge remote-tracking branch 'origin/master'
2021-05-11 11:00:10 +10:00
Max Cahill
f343c1c0b7
[modified] optimised table.insert_sorted
and made it _actually_ insert at the back of the range instead of at the first equal found position (not always the same)
2021-05-11 10:59:59 +10:00
Max Cahill
89ecd4258e
Merge remote-tracking branch 'origin/master'
...
# Conflicts:
# tablex.lua
2021-05-04 21:07:35 +10:00
Max Cahill
5cd33398a5
[added] tablex.swap
2021-05-04 20:52:47 +10:00
Max Cahill
bc7754ae0b
[modified] minor refactor of how tablex.clear
is or isn't initialised as needed
2021-05-04 10:38:31 +10:00
Max Cahill
826a2797c8
[modified] refactored insert_sorted to get PR #18 merged
2021-04-30 11:46:51 +10:00
Alvaro Frias Garay
5ed6d68f6c
added binary search to insert_sorted
...
Added method tablex.is_sorted
2021-04-15 21:09:04 -03:00
Max Cahill
16c183ec31
[added] tablex.take_random
which is like pick_random
but removes the element
2021-03-09 20:07:41 +11:00
Max Cahill
24bcc78616
[added] tablex.append_inplace
and tablex.append
can both take variable numbers of tables
2021-03-05 12:07:28 +11:00
Max Cahill
5f124be2f0
[added] tablex.trim to trim a table to a certain length
2020-08-24 20:54:43 +10:00
Max Cahill
18d02434a0
[added] tablex.flatten as an alias for collapse
2020-07-02 17:04:47 +10:00
Max Cahill
284856d2c3
[modified] refactored init.lua extensively; used new assert module in stringx and tablex
2020-05-19 12:03:45 +10:00
Max Cahill
f183a1a485
[fixed] a few wrong assert strings
2020-05-12 14:14:08 +10:00
Max Cahill
b91f4f1fcc
[added] tablex.collapse to reduce the dimensionality of a table; caveats on some edge case behaviour documented
2020-04-29 20:57:05 +10:00
Max Cahill
e75147ec77
[modified] moved tablex.stringify to stringx.pretty
2020-04-17 10:45:15 +10:00
Max Cahill
6bf6113dc2
[added] quoted strings in tablex.stringify; todo consider moving it to stringx actually, as it works for non-table types, maybe as stringx.pretty...
2020-04-17 10:34:39 +10:00
Max Cahill
d445c170e1
[added] tablex.insert_sorted (does what you'd expect, though no binary search yet)
2020-04-14 21:52:33 +10:00
Max Cahill
7922cd3912
[modified] table.push and table.unshift return the table for possible chaining
2020-04-14 13:53:10 +10:00
Max Cahill
b570ea7096
[added] tablex.front and tablex.key_of
2020-04-10 14:14:15 +10:00
Max Cahill
a87380f43c
[modified] moved dedupe from functional to tablex
2020-04-08 21:18:52 +10:00
Max Cahill
f214be9f59
[added] tostring awareness for tablex.stringify
2020-04-08 21:10:24 +10:00
Max Cahill
c191a7b4f6
[fixed] issue loading tablex without love
2020-04-08 20:51:16 +10:00
Max Cahill
8d5da0a9ff
[modified] moved append and append_inplace from functional to tablex
2020-04-08 20:50:51 +10:00
Max Cahill
6386aaf298
[modified] big refactor to localised modules and require("batteries"):export()
for global usage; renamed files table
to tablex
and math
to mathx
to allow using the library in your module root if you really want to.
2020-04-07 13:49:10 +10:00