wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-06-2009, 06:04 PM   #1
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default Pool

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!
__________________

Last edited by Rising_Dusk : 12-10-2009 at 06:24 AM. Reason: Updated
Rising_Dusk is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 12-06-2009, 08:36 PM   #2
Gamat
User
 
Gamat's Avatar
 
Join Date: Aug 2008
Posts: 40

Gamat has little to show at this moment (2)

Default

What about a CountItemsInPool?
Gamat is offline   Reply With Quote
Old 12-06-2009, 08:45 PM   #3
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 12-06-2009, 09:03 PM   #4
Gamat
User
 
Gamat's Avatar
 
Join Date: Aug 2008
Posts: 40

Gamat has little to show at this moment (2)

Default

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
Gamat is offline   Reply With Quote
Old 12-06-2009, 09:14 PM   #5
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 12-07-2009, 02:33 AM   #6
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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:	36
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
__________________

Last edited by Rising_Dusk : 12-07-2009 at 02:34 AM.
Rising_Dusk is offline   Reply With Quote
Old 12-07-2009, 02:34 AM   #7
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

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?

Last edited by weaaddar : 12-07-2009 at 02:37 AM.
weaaddar is offline   Reply With Quote
Old 12-07-2009, 02:53 AM   #8
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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 03:53 AM.
Rising_Dusk is offline   Reply With Quote
Old 12-07-2009, 04:13 AM   #9
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

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.
weaaddar is offline   Reply With Quote
Old 12-07-2009, 04:27 AM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 12-07-2009, 04:59 AM   #11
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

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.
weaaddar is offline   Reply With Quote
Old 12-07-2009, 12:44 PM   #12
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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: jpg Bench.JPG (4.3 KB, 400 views)
Attached Files
File Type: w3x TEST.w3x (54.3 KB, 30 views)
__________________

Last edited by Rising_Dusk : 12-07-2009 at 01:31 PM.
Rising_Dusk is offline   Reply With Quote
Old 12-08-2009, 05:54 AM   #13
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
Attached Images
File Type: jpg Bench.JPG (4.0 KB, 368 views)
__________________

Last edited by Rising_Dusk : 12-08-2009 at 05:54 AM.
Rising_Dusk is offline   Reply With Quote
Old 12-08-2009, 06:10 AM   #14
Pyrogasm
Lackadaisically Absent.
 
Pyrogasm's Avatar


Respected User
 
Join Date: Sep 2006
Posts: 4,523

Submissions (9)

Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)

Hero Contest - Fourth place

Send a message via ICQ to Pyrogasm Send a message via AIM to Pyrogasm Send a message via MSN to Pyrogasm Send a message via Yahoo to Pyrogasm
Default

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.
__________________
Quote:
Originally posted by Rising_Dusk
Your spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

The Spell Request Thread Done for, unless someone else wants to revive it...
It lasted a damn long time.

Please; Ask for Help Appropriately














Quote:
Originally posted by Kyrbi0
Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).
Quote:
Originally posted by Pyrogasm
Rome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.
Pyrogasm is offline   Reply With Quote
Old 12-08-2009, 06:43 AM   #15
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Sorry, I fixed that.
__________________
Rising_Dusk is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:32 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services