Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose double linked list to script #7194

Closed
SleepProgger opened this issue Nov 26, 2016 · 4 comments · Fixed by goostengine/goost#12
Closed

Expose double linked list to script #7194

SleepProgger opened this issue Nov 26, 2016 · 4 comments · Fixed by goostengine/goost#12

Comments

@SleepProgger
Copy link

There is a double linked list in godots source code (core/list.h).
It would be nice if that would be exposed as there are some cases where a double linked list performs way better as a vector based.
Especially when it comes to inserting/removing elements at any position except the end.

I could do some work on this, but am not sure how to handle locking and registering it (Although i could try to mirror the behavior of the Array class).
Basically exposing the list<Variant*> and list<Variant*>::Element should do the trick i guess .?
Implementing it as iterable should also work similar to how Array does it.

Additionally (and if requested i could open another issue for this) exposing the core/ring_buffer.h as queue would also be nice for queue needs.
It should perform better as a queue using a double linked list (and def. better as a vector based list) with the limitation that it has a "fixed" size and potential allocates unused memory ofc.
But there are cases where exactly this behavior is needed.

@ghost
Copy link

ghost commented Apr 8, 2018

Still reproducible/relevant in 3.1 master 9e7cee2 : such data stucture isn't exposed yet.

@Illiander
Copy link

Illiander commented Jan 5, 2019

Was about to post on reddit asking if there's a proper linked-list implementation I can use.

I need a fast FIFO list, and array isn't doing the job.

Just wrote this as an array replacement, and got significant speed improvements:

extends Node

var front_space = 0
var array_len = 0
var array_data = []

func push_back(val):
    if array_data.size() < front_space+array_len+1:
        enlarge()
    array_len += 1
    array_data[front_space+array_len-1] = val

func pop_back():
    if array_data.size() > array_len*8:
        reseat()
    array_len -= 1
    return array_data[front_space+array_len]

func back():
    return array_data[front_space+array_len-1]

func pop_front():
    if front_space > array_len:
        reseat()
    if array_data.size() > array_len*8:
        reseat()
    front_space += 1
    array_len -= 1
    return array_data[front_space-1]

func front():
    return array_data[front_space]

func size():
    return array_len

func enlarge():
    array_data.resize(front_space+array_len*2+1)

func reseat():
    var new_array = []
    new_array.resize(array_len*2)
    for i in range(array_len):
        new_array[i] = array_data[i+front_space]
    front_space = 0
    array_data = new_array

func print_debug():
    print("front: ", front_space,", len: ",arr

@akien-mga
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@Xrayez
Copy link
Contributor

Xrayez commented Nov 25, 2021

For those stumbling upon the issue, doubly linked lists are available in Goost via LinkedList class.

See also godotengine/godot-proposals#1522 if you'd like to see this implemented in Godot instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants