![]() |
#1 |
Obscurity, the Art
|
![]() 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:
![]() Function List: This library provides the following datatype to the user that can be used as shown. ![]() 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! Last edited by Rising_Dusk : 12-10-2009 at 07:24 AM. Reason: Updated |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
User
Join Date: Aug 2008
Posts: 40
![]() |
![]() What about a CountItemsInPool?
|
![]() |
![]() |
![]() |
#4 | |
User
Join Date: Aug 2008
Posts: 40
![]() |
![]() A pool is like a group, maybe the group/pool is empty, and it is good to know that in some cases.
|
|
![]() |
![]() |
![]() |
#5 |
Obscurity, the Art
|
![]() 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.
__________________ |
![]() |
![]() |
![]() |
#6 | ||||||||||||||||||||
Obscurity, the Art
|
![]() 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+.
![]() In the following testmap: TEST.w3x Last edited by Rising_Dusk : 12-07-2009 at 03:34 AM. |
||||||||||||||||||||
![]() |
![]() |
![]() |
#7 |
User
Respected User
Join Date: Apr 2002
Posts: 2,372
![]() |
![]() 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:: ![]() 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? Last edited by weaaddar : 12-07-2009 at 03:37 AM. |
![]() |
![]() |
![]() |
#8 |
Obscurity, the Art
|
![]() 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.
__________________Last edited by Rising_Dusk : 12-07-2009 at 04:53 AM. |
![]() |
![]() |
![]() |
#9 |
User
Respected User
Join Date: Apr 2002
Posts: 2,372
![]() |
![]() 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. |
![]() |
![]() |
![]() |
#10 |
Obscurity, the Art
|
![]() 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. |
![]() |
![]() |
![]() |
#11 |
User
Respected User
Join Date: Apr 2002
Posts: 2,372
![]() |
![]() 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 |
Obscurity, the Art
|
![]() 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: Using the attached testmap and following code: ![]() Last edited by Rising_Dusk : 12-07-2009 at 02:31 PM. |
![]() |
![]() |
![]() |
#13 |
Obscurity, the Art
|
![]() 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:
This was at 250 executions. Last edited by Rising_Dusk : 12-08-2009 at 06:54 AM. |
![]() |
![]() |
![]() |
#14 |
Lackadaisically Absent.
Respected User
|
![]() 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.
__________________ |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|