Page 1 of 1

DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:02 pm
by Archive-Poster
These stocks are meant to mimic Sourcemod's data packs functionality, and complement CellTrie/CellArray, allowing heterogeneous data in the same container to be accessed by index.

Storage is done in nested CellArrays, and there are no size limits other than those imposed by them, if any.

They'll be specially useful to pass data to/from callbacks and forwards.

Re: DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:08 pm
by Archive-Poster
Forgot to mention, indexes start at 0, and are ordered in first-in-first-out scheme.

E.g.:

Code: Select all

// Create
new Array:hPack = DataPack_Create()

// Insert
DataPack_PushCell(hPack, 1)
DataPack_PushString(hPack, "hello world")

// Test
DataPack_GetItemType(hPack, 0) // DPACK_CELL
DataPack_GetItemType(hPack, 1) // DPACK_STRING

// Retrieve
new any:cCell, szString[32]
DataPack_GetCell(hPack, 0, cCell)
DataPack_GetString(hPack, 1, szString, charsmax(szString))
// cCell == 1, szString == "hello world"

// Free
DataPack_Free(hPack)

Re: DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:35 pm
by Archive-Poster
hmmm, I'm not sure about the advantage of this over using the existing functions in cellarray.inc o_O

Can you clarify?
Arrays are homogenous containers. Each array can only contain data of one kind (cell or multicell). This is an abstraction layer for an array of "cells which values refer to arrays", being each one of the pointed to arrays a container of a different kind of data.

Code: Select all

Array 
{
  Array
  {
    cell,cell,cell...
  }
  Array 
  {
    multicell,multicell...
  }
}
If i understood it right. Anyway, good job.

Edit:

doesn't the file miss the stocks for CellTries?

Re: DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:38 pm
by Archive-Poster
The same as for Arrays the difference is that with Arrays you associate data to a cell, with Tries you associated data to a group of cells.

Code: Select all

native TrieSetCell(Trie:handle, const key[], any:value);
let me just leave you a tip:

You are doing

Code: Select all

if(!hDataPack)
   return
I wouldn't recommend that because you should let errors happen or handle them in your code so, the user can see what's the problem.

Re: DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:38 pm
by Archive-Poster
Makes sense, I'll change it so the CellArray functions will take care of validating the handles.

Re: DataPacks: Heterogeneous Container

Posted: Wed Aug 19, 2026 6:38 pm
by Archive-Poster
Thanks for the explanation! I assumed that the regular arrays were already heterogeneous.