Thinking about making a linked-list / tree plugin.

For developers using the Construct 2 Javascript SDK

Post » Thu Nov 20, 2014 3:28 pm

Hey all, :)

I'm considering creating a plugin/behavior that provides linked-lists or tree-style data structures.

I'm okay with building a list system from scratch if necessary, but if there's any list-type stuff natively accessible from within the C2 runtime, I'm also happy to just use that and avoid reinventing the wheel.

So if anyone knows off hand...
1. Does JavaScript have native data structure functionality or libraries?
2. Does jQuery? (available from C2 runtime I think?)
3. Should I consider using JSON?
4. If "yes" to any of the above, are they usable in the C2 runtime?

It looks to me like there may be generalized data structure tools available natively in JavaScript, and possibly JSON stuff in the standard library.
(e.g. see "Keyed collections" https://developer.mozilla.org/en-US/doc ... structures)

But I don't know if it's usable in the C2 runtime, as I'm not sure if there are any important support issues with different versions of JavaScript that I should be aware of.

Any thoughts or advice welcome. :)
Last edited by fisholith on Fri Nov 21, 2014 6:03 am, edited 2 times in total.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Thu Nov 20, 2014 3:33 pm

1. javascript has "array", and "object" (hash table)
2. I used JQuery only when it needs to have a html element. (But not all environments support JQuery I think.)
3. Yes, since C2 only has number and string type, JSON (string) could be used to store the date structure.
4. Yes, they all could be used.
B
109
S
27
G
278
Posts: 4,483
Reputation: 155,426

Post » Fri Nov 21, 2014 6:10 am

Thanks for the info @rexrainbow. :)

Do you have any advice on which way to go if I want my list/tree interactions to be fast?

1. I think arrays could work, if I link them together to form more complex structures. The first thing I was considering building was a plugin like the C2 Dictionary, but with each key linking to an array/list instead of a single value. That said, hash tables are actually closer to what I was looking for, so objects might be a good approach as far as performance goes.

2. Good to know. Yeah, JQuery looked like it was mostly aimed at DOM traversal and other webpage-y stuff.

3. JSON would be pretty nice if its not too slow.


1a. Do you know off hand if deleting a property from an object is likely to change its performance?

Quite a while back, I read about interpreter optimizations that assume that objects are usually used for OOP, for which property deletion is unlikely. With interpreters being optimized for that purpose, interaction with an object takes a permanent performance hit upon the first deletion of a property from that object.

The only thing I could find about this was a discussion of the Chrome engine from 2009, so it may not be an issue any more:
(see time 8:16) http://channel9.msdn.com/Shows/Going+De ... al-Machine


3a. How fast is JSON compared to using objects for data structure purposes?

For instance, with JSON, I'm not sure if the underlying code is moving between nodes by following references, or if it is actually parsing its way through large segments of JSON text. I would think that parsing text would be the slower method in general, but even if JSON is doing everything via text, for all I know it could be getting some kind of special treatment by the interpreter.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Fri Nov 21, 2014 6:35 am

You might consider performance optimize at last.
The most import thing is how to use this plugin in event sheet.
B
109
S
27
G
278
Posts: 4,483
Reputation: 155,426

Post » Fri Nov 21, 2014 9:06 am

Very good point. :)
Thanks again @rexrainbow.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Fri Nov 21, 2014 9:40 am

I am not sure what kind of design is suitable for event sheet, since the style of event sheet is not the same as text code.
B
109
S
27
G
278
Posts: 4,483
Reputation: 155,426

Post » Sat Nov 22, 2014 3:45 am

you can use javascript objects as hashtables/dictionaries, with each key being a branch of a tree, and each key can in turn store another object which is also a hastable/dictionary. This wouldn't be difficult at all so read about javascript!
B
79
S
13
G
8
Posts: 1,977
Reputation: 9,947

Post » Sat Nov 22, 2014 6:31 pm

Rex/R0j0 has a plugin(Hashtable) that let's you store data in a tree like structure. I think the question asked is wrong.

"Should I make a Linked List or Tree data structure"
But instead
"What data storage do I/you need"

The second question is a lot more valid and also the question how to use the storage in the event sheet.

What I will add is this. A depth storage system would be helpful. however Hashtable already accomplishes this However I find Hashtable "string.access.level" style of storage to not so easily usable from an event sheet as it is from traditional programming. But I see no way to make it any easier than it is. Now if you can make depth storage use variable paramater passing that would be a win. Other wise my goto depth storage is still hashtalbe.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Mon Nov 24, 2014 3:02 am

Like @jayderyu said "What data storage do I/you need". You might define your aimed problem first.

Here is another plugin which has tree nodes.
Image
B
109
S
27
G
278
Posts: 4,483
Reputation: 155,426


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests