#Lists data structure exist in zig?
1 messages · Page 1 of 1 (latest)
what is the difference between list and std.ArrayList?
list as in a linked list?
std.SinglyLinkedList
you can also look this up in the language reference
it's not clear what they want from list. If you want dynamically growing container, use ArrayList. If you want linked list, without contiguous memory layout gurantee then use the SinglyLinkedList. Then if you want mix of ArrayList and SinglyLinkedList, there is a SegmentedList - large parts of it will be contiguous runs of memory, but on resize, instead of reallocating everything, new segment will be allocated somewhere else in memory
In zig a struct is an array at the background?
no, struct is unique class of types in zig. Sure you can view everything as string of bytes, but struct is a specific concept in the language, different from array
Well im trying to have a struct that works with lists in the background
elaborate
Maybe I need to see how the struct works underneath first.
i mean you can always bitcast from struct to array, but idk what you're doing
Bitcasting could be useful if you say received bytes from file or network, store them in array of u8, then bitcast it to struct you know those bytes represent
I have this c++ code, how would be the zig alternative/implementation?
struct snodo {
void * Data;
snodo * Next;
snodo(void * nData)
{
Data = nData;
Next = NULL;
};
snodo()
{
Data = NULL;
Next = NULL;
}
};
class Tree
{
public:
snodo* root;
snodo* current;
snodo* currentAux;
snodo* currentBefore;
int count;
Tree() {
root = NULL;
count = 0;
}
void Add(void *Data);
bool Goto(int index);
bool GotoAux(int index);
int GetSize() { return count; }
int GetSizeb() { return count; }
void* GetData(int i) { Goto(i); return current->Data; } // depues de recorerlos y llegar la posicion i
void Link(int root, int son, int pos);
};