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!
ZScript dynamic array suggestions
Moderator: GZDoom Developers
- Sarah
- Posts: 551
- Joined: Wed Sep 06, 2006 12:36 pm
- Preferred Pronouns: She/Her
- Operating System Version (Optional): Debian 11 (bullseye), Windows 10
- Location: Middle of Nowheresville Il.
- Contact:
Re: ZScript dynamic array suggestions
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.
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.
Re: ZScript dynamic array suggestions
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
I mean, do-able but as I said, hacky and makes code harder to read and maintain.
Code: Select all
class WrapperClass
{
Array<someType> contents;
}
let arr = new("WrapperClass");
arr.contents[i] = whatever;
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49056
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript dynamic array suggestions
It's a known issue biut not easy to fix because the VM doesn't know anything about array references.