HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Binary Search Tree?

05-12-2004, 07:59 PM#1
SADISM
I was wondering if anyone has tried to setup some sort of a binary search tree in jass. I myself was thinking of putting one together, but as I'm not very adept at programming, I'll have to do some more reading up. Perhaps this could be made into some sort of a challenge, if enough people are interested in it.

Edit - I think I'm going to put together a red/black tree or an avl tree.
05-12-2004, 08:59 PM#2
The Gearhead
By binary search tree, what are you trying to do?

Edit: I looked at some binary tree diagrams..

And I must say, they have very little apparent purpose.

Care to explain what you might use a binary tree for? I mean, there may be an easier way.
05-12-2004, 09:05 PM#3
SADISM
I wanted to put something together that could store my data, and allow me to access it rather quickly with a string name - but I don't want to use game cache. I was looking at the heap challenge people did a while back, but I figure if I make a good tree, then I wouldn't even need to use a heap. However, like game cache I want to be able to just input a string key, and get out my integer value.

I figured the best place for me to start would be to have a way to compare strings using some sort of charactermap so I could compare the keys I would using to branch down into my tree, so I made somes functions to do just that.

At first glance, most basic binary trees seemed rather bland. However, when I started looking at trees that rebalanced themselves (avl and red/black) as nodes were deleted or inserted, it seemed to me that they would be a rather efficient method for what I want.
05-12-2004, 10:34 PM#4
AIAndy
Why do you not want to use gamecache ? It is the most efficient way of accessing data by string in JASS.
05-12-2004, 10:47 PM#5
The Gearhead
Why not just use a variable.

Variables, can be named, manipulated at will, and referenced faster than anything else.

Simply make a global variable, and in JASS reference it as udg_GlobalVariableName.

So, if you use ctrl-B and make a global variable called "IntegerValueOne" then in JASS you reference it using udg_IntegerValueOne.

It's very simple, allows complex naming sequences, and it gets the job done.
05-12-2004, 10:53 PM#6
SADISM
Is it? I've looked up about it on various forums, but haven't really found out all too much about game cache, besides that it is not saved when a game on bnet ends, and that it supposedly stores information on the hard drive. Because of a lack of apparent answers in my searching, I was unsure whether or not to use game cache, as I want a memory efficient data storage system, that is also easy to use on my part making the map.

I guess I still have a few questions about game cache, like where it is stored during a game, or a memory comparison between it and some similar system, which I guess a binary tree that uses string keys would be. Although from my personal experience, it seems that using game cache takes up more memory than when using a similar array system; not to mention, that arrays are definitely faster. But if anyone could answer those questions or shed more light on game cache, then I guess I could come up with a better decision on what I should do. Thanks ahead of time.

@Gearhead: I would rather not use just numerous single variables, as I don't want to have to manually create upwards of 2000-3000 variables, which is at least how many I'll need to reference by the time I'm done. Basically, I need a system that can handle lots of variables efficiently, but also easy enough to setup that I can understand and create it - which is why I was looking at binary trees.

Edit: I'm not very knowledgeable about various ideas related to programming (data structures, etc.) as my sole experience is with JASS. But I do know JASS, and am writing triggers for my map only in JASS. Just in case you guys were wondering where I stand.
05-13-2004, 09:12 AM#7
AIAndy
While accessing arrays is faster, you do not only access the array once when you implement a tree or similar data structures. And especially decomposing the string to search through the data structure is not cheap either.
While the gamecache was implemented to allow transfer of data between single player maps, it is actually pretty effecient. The data structure behind it is a hash table and since all the computations are done in the native code and not in script, it is pretty fast and it is very unlikely that you will be able to make anything faster to store key/value pairs. The gamecache also works in multiplayer, you just can't save it but you will not do that for this usage anyway.
The conclusion is that while not saved, the gamecache is an efficient associative array and useful for any kind of data lookup (where a simple array is not enough).
I have even implemented an entire class system with polymorphism and inheritance based on gamecache.
05-13-2004, 12:38 PM#8
The Gearhead
There is a problem wrong with making two identical arrays, in which one contains a string and one contains a value?


I see no point in a binary search tree, they are inefficient in searching, look at the various methods. The methods include: going left to right, one by one, until the right value is reached. Going down the far left side, then the next path, and so on until the last path is the far right side. And the other methods are reversals of the above.

All in all, it takes more time than accessing a string or integer!
05-13-2004, 09:57 PM#9
AIAndy
You obviously did not really look into the matter, Gearhead.
Binary search trees are pretty efficient search structures ( O(log n) ).
An unsorted array with the keys takes O(n). A sorted array takes O(log n) but is worse when inserting/deleting elements.
05-13-2004, 10:07 PM#10
The Gearhead
The amount of string leakage induced by having a binary search tree is absolutely ludicrous.

As far as efficiency, I'd keep with arrays. Or, as AIAndy said, gamecache.

You could code a tree, but the operations would be rediculously complicated for very little use.
05-14-2004, 02:14 PM#11
Flakey
It's not to bad to do...you just create a referencing system like in java (or a pointer in c/c++) where a recursive function passes the reference to the next variable, which in turn will have a reference to next and so on.
Using gamecache these references can then be used to retrieve the next variable, thus creating the data structure required.
With regard to the data you just make sure that you collect garbage on the fly as you alter the data ensuring that the gamecache will not be cluttered by unnecessary data.
I'll have a go and get back to you.
05-14-2004, 02:49 PM#12
AIAndy
You do not even need the tree then and can lookup the data directly with gamecache.
05-14-2004, 08:51 PM#13
The Gearhead
As an analysis and database tool, the binary search tree is useless. I surmise that the methods used today are infinitely more complex, and far more capable of handling far larger amounts of data in a much shorter amount of time.

From a PHP based forum:
Quote:
[ Script Execution time: 0.0847 ] [ 12 queries used ] [ GZIP Enabled ]

Powered by Invision Power Board(U) v1.2 © 2003 IPS, Inc.

It near instantly sorts, retrieves, and catagorizes data. A binary tree, especially when coded in JASS, would cause unnecessary mayhem and memory leaks.
05-15-2004, 12:00 AM#14
SADISM
Thanks guys for your input. I'll probably end up using gamecache and arrays together: arrays for things that need quick accessing, and gamecache for the rest. I'll probably try to put together a binary tree for fun after my map is done.
05-15-2004, 12:52 AM#15
joseka
Quote:
Originally Posted by SADISM
Thanks guys for your input. I'll probably end up using gamecache and arrays together: arrays for things that need quick accessing, and gamecache for the rest. I'll probably try to put together a binary tree for fun after my map is done.

Hey maybe there is a way to do a binary tree , !!!using arrays!!!, but you will have a good headache trying to create the neccesary functions to add and delete and order and mores "ands" to do this system . Look at this web in the the part of arrayed binary trees:
http://www.gamedev.net/reference/art...rticle1433.asp

Have a lot of fun trying to do that , heck maybe this thing should be in the map week contest umm....
^_^