Merge branch 'feature/pairs' into dev

This commit is contained in:
BlackMATov
2025-09-01 15:49:46 +07:00
4 changed files with 269 additions and 248 deletions

View File

@@ -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
```
@@ -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
```

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff