Linked list implementation in PAWN -
BigETI - 22.11.2017
This is a linked list implementation in PAWN.
Project
The source code and documentation are located at GitHub: https://github.com/BigETI/pawn-list
Re: Linked list implementation in PAWN -
ball - 03.05.2018
What is the difference between LIST_push_back_* and LIST_push_front_*? I read documentation of this, but still I don't get it, for example
Код:
new List:list;
LIST_push_back_str(list, "This is a test");
Код:
new List:list;
LIST_push_front_str(list, "This is a test");
What is the difference?
@down: Oh, thanks. I thought that there are indexes to store data like normal arrays.
Re: Linked list implementation in PAWN -
BigETI - 03.05.2018
Quote:
Originally Posted by ball
What is the difference between LIST_push_back_* and LIST_push_front_*? I read documentation of this, but still I don't get it, for example
Код:
new List:list;
LIST_push_back_str(list, "This is a test");
Код:
new List:list;
LIST_push_front_str(list, "This is a test");
What is the difference?
|
It's pretty easy to understand:
One pushes the value at the back (end) of the list, and the other one pushes the value at the front (begin) of the list.
Let's simulate a "push back" and a "push front":
Given a list:
Let's push "D" at the back of the list
after that let's push "E" at the front of the list
Код:
E -> A -> B -> C -> D
Re: Linked list implementation in PAWN -
ball - 03.05.2018
Thanks, now I got it. So I give it a try and got some code from documentation at github, there are some errors, not big, but if you want to know.
Код:
new List:list, value[16], m_v_sz, v_sz;
LIST_push_back_str(map, "This is a test);
LIST_push_back_str(map, "foo");
LIST_push_back_str(map, "bar");
LIST_foreach(v : list)
{
v_sz = MEM_get_size(v);
m_v_sz = ((v_sz < sizeof value) ? v_sz : sizeof value);
MEM_zero(UnmanagedPointer:MEM_get_addr(value[0]), sizeof value);
MEM_get_arr(v, _, value, m_v_sz);
printf("0x%x, %d, \"%s\"", _:v, v_sz, value);
}
This is at LIST_foreach.
Код:
error 017: undefined symbol "map"
Код:
new List:list, value[16], m_v_sz, v_sz;
LIST_push_back_str(map, "This is a test); //also there is a lack of " near test
But I wanted to ask about this line, gives error
Код:
MEM_zero(UnmanagedPointer:MEM_get_addr(value[0]), sizeof value);
Код:
error 017: undefined symbol "MEM_get_addr"
I checked file memory.inc and there is lack of this function, but I commented this line and everything seems to be working as expected, is this line necessary?
Re: Linked list implementation in PAWN -
BigETI - 03.05.2018
Код:
MEM_zero(UnmanagedPointer:MEM_get_addr(value[0]), sizeof value);
which should be
Код:
MEM_UM_zero(UnmanagedPointer:MEM_UM_get_addr(value[0]), sizeof value);
ensures, that "value" has been set to zero at all cells, because "m_v_sz" can be "v_sz" or "sizeof value", where "v_sz" is not always "sizeof value".
Documentation should be fixed now, thank you.
Re: Linked list implementation in PAWN -
ball - 03.05.2018
Код:
MEM_zero(UnmanagedPointer:MEM_UM_get_addr(value[0]), sizeof value);
Now line gives warning "tag mismatch", but I changed tag to "Pointer" and warning disappeared.
Код:
MEM_zero(Pointer:MEM_UM_get_addr(value[0]), sizeof value);
Re: Linked list implementation in PAWN -
BigETI - 03.05.2018
Either way MEM_zero will not work with a pointer, that wasn't created with MEM_new_* or MEM_clone.
MEM_UM_zero should have been used for this. My bad...