Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Why is ValueNthElementKey works only for array/map/function but not for sciter Object type #22

Closed
oskca opened this issue Feb 28, 2016 · 2 comments

Comments

@oskca
Copy link

oskca commented Feb 28, 2016

See sciter-sdk/go-sciter#17. In order to get the keys of an sciter object type, one have to use EnumerateKeyValue, because ValueNthElementKey(idx) always returns NULL value.

{
    "string":"hello",
    "number":123
}

While ValueElementsCount both works on array/map/function and on sciter Object type, should ValueNthElementKey supports all those composit types?

@c-smile
Copy link
Owner

c-smile commented Feb 28, 2016

Script object is an unordered map of name/value pairs so it does not provide indexed access.
Moreover internal implementation of object inside script is pure hash map with collision lists.
Getting nth-element key/value from object is O(N) complex operation. And if you want to do something like this :

for( int n = 0; n < length; ++n)  
  VALUE k = ValueNthElementKey(obj, idx);

You will get O(N*N) complex operation. I simply don't want even to enable this possibility in API.

Options:

  • Use ValueIsolate(obj) - after the call all script objects will be converted to JSON dictionaries (that have indexed access by design).
  • Use EnumerateKeyValue

@c-smile c-smile closed this as completed Feb 28, 2016
@oskca
Copy link
Author

oskca commented Feb 29, 2016

Thank you for you explanation. That makes good sense for me 😄

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

No branches or pull requests

2 participants