Discuss Scratch

_Solaris
Scratcher
2 posts

Faster List Search

I'm trying to create a project where a long list (256 elements) is being searched every fourth loop in a “run without screen refresh” block. The project had manageable framerates until I used the "item # of () in " block, at which point it tanked significantly. The slowdown is directly proportional to the element's position within the list, with earlier elements not affecting the speed at all and later elements grinding the project to a halt. I think Scratch is trying to search the list using sequential search, which is inefficient compared to other search algorithms. I would like to use binary search, but the elements in the list are Unicode symbols (range 2200h to 22FFh) and I can't see any way to convert them to their numerical values.

Does anyone know of a more efficient search algorithm I could use?
09878901234321
Scratcher
500+ posts

Faster List Search

You can convert the Unicode symbols to their numerical values by just adding 0 to the hex values. (You would need to remove the h at the end)
join0xhexvalue+For 22FF returns 8959

Powered by DjangoBB