mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 04:00:14 +07:00
Compare commits
14 Commits
6b4c6f2a9a
...
59fb4d8ea4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59fb4d8ea4 | ||
|
|
001e6f2956 | ||
|
|
fb6d13ca74 | ||
|
|
8f61a14db6 | ||
|
|
0c016f1b67 | ||
|
|
26bf586140 | ||
|
|
46f1516a55 | ||
|
|
4cd8393546 | ||
|
|
22302cee75 | ||
|
|
d4a7c7b77c | ||
|
|
12beee6eec | ||
|
|
71a7d382c1 | ||
|
|
f2a8ee5b83 | ||
|
|
81bf1d91e9 |
16
README.md
16
README.md
@@ -147,16 +147,15 @@ function evolved.alive_any(...) end
|
||||
Sometimes (for debugging purposes, for example), it is necessary to extract the index and version from an identifier or to pack them back into an identifier. The [`evolved.pack`](#evolvedpack) and [`evolved.unpack`](#evolvedunpack) functions can be used for this purpose.
|
||||
|
||||
```lua
|
||||
---@param primary integer
|
||||
---@param secondary integer
|
||||
---@param index integer
|
||||
---@param version integer
|
||||
---@return evolved.id id
|
||||
---@nodiscard
|
||||
function evolved.pack(primary, secondary) end
|
||||
function evolved.pack(index, version) end
|
||||
|
||||
---@param id evolved.id
|
||||
---@return integer primary
|
||||
---@return integer secondary
|
||||
---@return integer options
|
||||
---@nodiscard
|
||||
function evolved.unpack(id) end
|
||||
```
|
||||
@@ -1098,7 +1097,7 @@ id :: integer? -> id...
|
||||
name :: id... -> string...
|
||||
|
||||
pack :: integer, integer -> id
|
||||
unpack :: id -> integer, integer, integer
|
||||
unpack :: id -> integer, integer
|
||||
|
||||
defer :: boolean
|
||||
commit :: boolean
|
||||
@@ -1304,11 +1303,11 @@ function evolved.name(...) end
|
||||
### `evolved.pack`
|
||||
|
||||
```lua
|
||||
---@param primary integer
|
||||
---@param secondary integer
|
||||
---@param index integer
|
||||
---@param version integer
|
||||
---@return evolved.id id
|
||||
---@nodiscard
|
||||
function evolved.pack(primary, secondary) end
|
||||
function evolved.pack(index, version) end
|
||||
```
|
||||
|
||||
### `evolved.unpack`
|
||||
@@ -1317,7 +1316,6 @@ function evolved.pack(primary, secondary) end
|
||||
---@param id evolved.id
|
||||
---@return integer primary
|
||||
---@return integer secondary
|
||||
---@return integer options
|
||||
---@nodiscard
|
||||
function evolved.unpack(id) end
|
||||
```
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
- add INDEX fragment trait
|
||||
- use compact prefix-tree for chunks
|
||||
- optional ffi component storages
|
||||
- add EXCLUSIVE fragment trait
|
||||
|
||||
## Thoughts
|
||||
|
||||
|
||||
@@ -13,21 +13,8 @@ for _ = 1, 1000 do
|
||||
local initial_secondary = math.random(1, 2 ^ 20 - 1)
|
||||
|
||||
local packed_id = evo.pack(initial_primary, initial_secondary)
|
||||
local unpacked_primary, unpacked_secondary, unpacked_options = evo.unpack(packed_id)
|
||||
local unpacked_primary, unpacked_secondary = evo.unpack(packed_id)
|
||||
|
||||
assert(initial_primary == unpacked_primary)
|
||||
assert(initial_secondary == unpacked_secondary)
|
||||
assert(0 == unpacked_options)
|
||||
end
|
||||
|
||||
for _ = 1, 1000 do
|
||||
local initial_primary = math.random(1, 2 ^ 31 - 1)
|
||||
local initial_secondary = math.random(1, 2 ^ 31 - 1)
|
||||
|
||||
local packed_id = evo.pack(initial_primary, initial_secondary)
|
||||
local unpacked_primary, unpacked_secondary, unpacked_options = evo.unpack(packed_id)
|
||||
|
||||
assert(initial_primary % 2 ^ 20 == unpacked_primary)
|
||||
assert(initial_secondary % 2 ^ 20 == unpacked_secondary)
|
||||
assert(0 == unpacked_options)
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@ local evo = require 'evolved'
|
||||
do
|
||||
local id = evo.id()
|
||||
|
||||
local index, version, options = evo.unpack(id)
|
||||
assert(evo.name(id) == string.format('$%d#%d:%d:%d', id, index, version, options))
|
||||
local index, version = evo.unpack(id)
|
||||
assert(evo.name(id) == string.format('$%d#%d:%d', id, index, version))
|
||||
|
||||
evo.set(id, evo.NAME, 'hello')
|
||||
assert(evo.name(id) == 'hello')
|
||||
@@ -13,7 +13,7 @@ do
|
||||
assert(evo.name(id) == 'world')
|
||||
|
||||
evo.destroy(id)
|
||||
assert(evo.name(id) == string.format('$%d#%d:%d:%d', id, index, version, options))
|
||||
assert(evo.name(id) == string.format('$%d#%d:%d', id, index, version))
|
||||
end
|
||||
|
||||
do
|
||||
|
||||
482
evolved.lua
482
evolved.lua
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user