PDA

View Full Version : Advantage of keyvalue over readfileline?


Chdata
11-17-2014, 15:46
I want to make a simple list formatted like this:

map_name int

arena_watchtower 200
arena_well 300

For example.

Is there any advantage to use keyvalues setup like

"thing"
{
"arena_watchtower" "200"
"arena_well" "300"
}

As opposed to a ReadFileLine while loop

I also intend to make a command that can write to this file to add a new map or change the value of an existing map.

Powerlord
11-17-2014, 16:40
The biggest advantage would be if you're storing things like this:

"myfile"
{
"arena_watchtower"
{
"time" "200"
"bacon" "tasty"
}
"arena_well"
{
"time" "300"
"bacon" "soggy"
}
}

...because you can use KvJumpToKey to jump directly to arena_well without having to parse arena_watchtower first.

Chdata
11-17-2014, 22:36
What's the difference between using trie/hashmaps and having a long string and StrContains or FindStringInArray

Powerlord
11-18-2014, 00:39
What's the difference between using trie/hashmaps and having a long string and StrContains or FindStringInArray

With a Trie/HashMap, the key is a String and the value is whatever you set. In an adt_array/ArrayList, they key is an incremented number and the value is whatever you set (in your example, presumably a String).

i.e. with a Trie, I can store "arena_nucleus", "500" but in an adt_array, I'd have to store 1, "arena_nucleus"... or have a REALLY large array (501 elements minumum to store 500, "arena_nucleus")

However, do be aware that Trie/HashMap currently has no way of fetching the list of keys... unless this changed in 1.7.

VoiDeD
11-19-2014, 13:36
What's the difference between using trie/hashmaps and having a long string and StrContains or FindStringInArray

The most important difference is the data structure itself. Tries give you O(1) lookup time compared to an array's FindStringInArray that will require O(n) time.

However, do be aware that Trie/HashMap currently has no way of fetching the list of keys... unless this changed in 1.7.

Iteration via trie snapshots was implemented quite a while ago (https://bugs.alliedmods.net/show_bug.cgi?id=5892).

Powerlord
11-19-2014, 13:49
Iteration via trie snapshots was implemented quite a while ago (https://bugs.alliedmods.net/show_bug.cgi?id=5892).

It was removed again (https://github.com/alliedmodders/sourcemod/commit/9f9f2baae2aaa6b3c399d4d0d7d8a3f1608282ab) more recently than that. At least from 1.6.

VoiDeD
11-19-2014, 13:59
Interesting. It's still alive and kicking in 1.7, which is the premiere branch to be using for any sane development with the transitional syntax anyway.

Mitchell
11-19-2014, 14:35
Interesting. It's still alive and kicking in 1.7, which is the premiere branch to be using for any sane development with the transitional syntax anyway.

sane development at the lose of compatibility?

VoiDeD
11-19-2014, 15:03
Be a transitional syntax purist. Don't support anyone still using 1.6.

I mean, there are ways to use some of the transitional syntax without breaking 1.6 compatibility: you just have to avoid using the native methodmap functions. But this is painful and you lose some of the benefits of using 1.7 in the first place.

Powerlord
11-19-2014, 15:15
Be a transitional syntax purist. Don't support anyone still using 1.6.

I mean, there are ways to use some of the transitional syntax without breaking 1.6 compatibility: you just have to avoid using the native methodmap functions. But this is painful and you lose some of the benefits of using 1.7 in the first place.

Large sections of the SM API aren't yet converted over to the 1.7 syntax. Some BAILOPAN has already finished and are currently pull requests awaiting review... but other parts, such as Timers, remain untouched..

Timers not being changed may be because of the CreateTimer arguments. The any tag... doesn't really fit the 1.7 syntax and is going away entirely in 1.8 (https://github.com/alliedmodders/sourcemod/pull/202) (see dvander's last comment in that pull request).