HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Pool

12-06-2009, 06:04 PM#1
Rising_Dusk
Pool Library

Background:
This is a library of code that gives you access to the pool data structure for integers. This finds the most use in maps where you want random numbers to be weighted so that certain outcomes are more probable than others.

Requirements:
  • (None)
Code:
Expand Library:

Function List:
This library provides the following datatype to the user that can be used as shown.
Expand JASS:

I submitted this mostly because the approach used in this library is relatively slow, requires a library when it doesn't need to, and one version of it doesn't compile. This library matches the functionality of that one, is O(1) in create/destroy versus O(n) in that one's destroy, and doesn't have the library requirement of LinkedLists. Furthermore, I find that stringpools and handlepools are useless, as you can just use an intpool with entries that are array indexes for any other type. Poot helped me with the framework of this and I finished it up for release. Hopefully someone else finds it as useful as I do.

Enjoy!
12-06-2009, 08:36 PM#2
Gamat
What about a CountItemsInPool?
12-06-2009, 08:45 PM#3
Rising_Dusk
Pool != Stack != List. There is no use for counting items in a pool, because you would not use a pool if you needed to count things in it.
12-06-2009, 09:03 PM#4
Gamat
A pool is like a group, maybe the group/pool is empty, and it is good to know that in some cases.

Hidden information:
Collapse JASS:
globals
intpool ipp

boolean array BOOLEAN
endglobals

function myfunc takes nothing returns nothing
    call BJDebugMsg(I2S(ipp.getRandomInt()))
endfunction

function addtoPool takes nothing returns nothing

if BOOLEAN[1] == true then
    call ipp.addInt(5, 1)
endif

if BOOLEAN[2] == true then
    call ipp.addInt(6, 1)
endif

if ipp.countItems() > 0 then
    call myfunc()
endif

endfunction
12-06-2009, 09:14 PM#5
Rising_Dusk
If it is empty, then .getRandomInt will return INTPOOL_NO_ENTRIES. Anyways, a pool is not like a group, you do not do actions upon the entire pool. You get random entries from the group, that's all you'll do with it.
12-07-2009, 02:33 AM#6
Rising_Dusk
I did some benchmark's of Pyro's Pools versus my Pool in this thread. I came up with the following results @ 1250 iterations. It's worth noting that I had to use only 1250 iterations because Pyro's Pools crashed the thread at 1500+.
Click image for larger version

Name:	Benchmark.JPG
Views:	33
Size:	14.8 KB
ID:	46846
Create:
Dusk's0.016
Pyro's0.052
Add:
Dusk's0.025
Pyro's0.151
Remove:
Dusk's0.027
Pyro's0.133
Destroy:
Dusk's0.009
Pyro's0.049
Using the following code:
Expand JASS:

In the following testmap:
TEST.w3x
Attached Images
File type: jpgBenchmark.JPG (14.8 KB)
Attached Files
File type: w3xTEST.w3x (59.8 KB)
12-07-2009, 02:34 AM#7
weaaddar
First, your variable names are terrible. o,r,c are not very meaningful.

second, I'm convinced that wrapping an itempool or a unitpool would be faster because a lot more of the code will happen in native space then slow jass function land. The function interface becomes a little uglier but this will probably be more performant.

Doing something like::
Expand Zinc:

Now if you provide a stack of some of the hundreds of regular item types you can use this faster moving pool. Sure you can't get the wieght after you added the thing, but who cares?
12-07-2009, 02:53 AM#8
Rising_Dusk
I was going to do the benchmarks, but yours won't compile in the testmap I provided above in place of my library. I also find it very lame that the user must provide as many valid item ids to addInt as they do entries. Lastly, I am not exactly sure that it would be faster. Once you factor in the stack handling for the item ids and the fact that you're actually creating a handle and doing that is slow, it may be just as fast as mine if not a bit slower.
12-07-2009, 04:13 AM#9
weaaddar
you probably have to rename the library, and I tested it compiled and spewed results but not much else. Are you using the latest Jasshelper?

I agree completely it would suck to have to provide itemtypes. But if the users have a small set, and I imagine the pool is relatively static, you can probably get away with it pretty handily.

Creating a handle is probably going to be faster then getting a random number, and suffering that nasty o(n) int fetch.
12-07-2009, 04:27 AM#10
Rising_Dusk
It compiles, but you didn't make your struct public so it didn't work in my benchmarking map. That's what the problem was. Anyways, for purposes of benchmarking, I need something like 1000 unique item id's.

If I'm particularly motivated, I will use GMSI to pull all item ids from standard WC3 and benchmark with them. Until such time as that benchmark can be done, can't really say which would be better. Gotta say, though, definitely need to abstract the stack of item ids away from the user. The user really shouldn't have to deal with that on their own.
12-07-2009, 04:59 AM#11
weaaddar
Yeah, can you try a simple exampler, just to test fetch speed which should be the slowest fetcher?

Try adding 5 things to each pool and just ask for a result like a couple thousand times see which is better. If the native creating and removing is really that costly then I'll concede my request.
12-07-2009, 12:44 PM#12
Rising_Dusk
That wouldn't be too tough if I test just the get. I'll do so.

EDIT:
Just tested the getRandomInt for both systems @ 1250 iterations apiece to the following results:
Zoom (requires log in)
Using the attached testmap and following code:
Expand JASS:
It would appear that handle creation is slow enough to make mine faster to use by a factor of nearly 10.
Attached Images
File type: jpgBench.JPG (4.3 KB)
Attached Files
File type: w3xTEST.w3x (54.3 KB)
12-08-2009, 05:54 AM#13
Rising_Dusk
I wanted to test a more extreme case for my library and see how well it performed. That last test was with only 1 entry in my intpool, so it might not be that representative. The test in this post was made with 50 entries in my pool, which is a lot for any pool. It still outperformed the itempool method you proposed, Weadd. See below:
Zoom (requires log in)
This was at 250 executions.
12-08-2009, 06:10 AM#14
Pyrogasm
Saying that my library doesn't even compile is not entirely true. It does compile, but the version I wrote that was supposed to use Stack doesn't, and rightly so because I never syntax checked it.
12-08-2009, 06:43 AM#15
Rising_Dusk
Sorry, I fixed that.