ZScript dynamic array suggestions

Remember, just because you request it, that doesn't mean you'll get it.

Moderators: Developers, ZDoom.org Team

ZScript dynamic array suggestions

Postby Nash » Sat Oct 07, 2017 12:45 pm

1) Pass arrays into functions directly.

2) Array sorting (preferably a fast algorithm that's not bubble sort cuz that's quite slow when dealing with thousands of items).

3) Count how many occurrences of something specific is in the array.

Thanks!
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: ZScript dynamic array suggestions

Postby Nero » Thu Oct 12, 2017 3:02 am

For suggestion 1, I'm a bit surprised this isn't already possible. If I'm stuck with just arrays, Z-Windows will need this in order to process groups of elements; from reading the page on pointers it doesn't appear I can create linked lists which is a bit of a downer. Be nice to have this and actual *pointers.

This page gives a nice overview of the various sorting methods out there. My vote would be on a merge sort as the time complexity seems to remain fairly constant with large arrays. Basically sorting often results in O(n^2) for a worst case scenario regardless of algorithm. I think what I would do, if I knew my arrays were likely to contain thousands of items, I would implement some sort of pre-sorting as part of array insertion.

Counting occurrences is probably doomed to be a linear method. If you could pass the array into a method it wouldn't be hard to implement in your own code.
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Re: ZScript dynamic array suggestions

Postby Nash » Thu Oct 12, 2017 5:44 am

Passing dynamic arrays around is currently VERY hacky; you make a "wrapper" class declaring your dynamic array in there, then pass the array by doing

Code: Select allExpand view
class WrapperClass
{
    Array<
someTypecontents;
}

let arr = new("WrapperClass");
arr.contents[i] = whatever;
 


I mean, do-able but as I said, hacky and makes code harder to read and maintain.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: ZScript dynamic array suggestions

Postby Graf Zahl » Thu Oct 12, 2017 6:26 am

It's a known issue biut not easy to fix because the VM doesn't know anything about array references.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Feature Suggestions

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest