Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18

Thread: Sorting skills by mana cost

  1. #11
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,551

    Default

    They're not even (ASH) arrays, really. You do a foreach on an ASH array, you get keys from 0 to n and the values are whatever is in the array.
    You do a foreach on a PluralValue, you get the "keys" as the various elements and the value - should you care to look - will be "true".
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  2. #12
    Developer
    Join Date
    Nov 2008
    Location
    Paris, France
    Posts
    4,510

    Default

    I never really understood what an array was, in ASH. It it just a map indexed by keys 0 to n with only one dimension?
    Try the Nemesis Quest Script or the FamiliarFeeder interface.
    *shakes KoLMafia tech support magic 8-ball* Update mafia to the latest daily .JAR!
    NEW Dad ASCENSION STARTED 20120730
    ------------------------------
    Welcome to Parenthood, Noob

  3. #13
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,551

    Default

    It looks and behaves that way, but is implemented internally in terms of java arrays. Either a map or an array is, really, one dimensional; multi-dimensional ones are simply maps or arrays whose values are maps or arrays.

    item [12] array;

    Can use keys 0 - 11. You get a runtime error if you use any other key. It always uses memory to hold 12 items, even if you only use a couple of them. But it's a constant time - O(1) - to access any element.

    item [int] map;

    Can use any int as a key. It has constant memory for the Java map, and additional memory for each element in the map, but is O( log n) to access any particular element.

    Each has its use.

    If you are able to use (a fairly densely packed set of) integers as keys, your program will be faster and use (potentially) slightly more memory.
    If you have a sparse set of integers, you can still use an array and get fast access, but you will waste a lot of memory.
    If you can't use integers as keys or don't want to waste memory on a sparse array, you can have a slower but less memory consuming map.
    Last edited by Veracity; 04-17-2011 at 12:27 AM.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  4. #14
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,623

    Default

    Thanks Veracity, that's very useful info and should probably be in the ASH Wiki.

    I wasn't picking a nit with Bale's remark. I just wanted to avoid confusion, since plural constants (which are commonly used and could easily be assumed to be maps) are not quite arrays and not quite maps, and many people don't even seem to realize ASH arrays exist. I'd actually assumed they would be sorted by key until fairly recently. If I assumed it, it's probably fair to say that others would too.

    This might be a good opportunity to ask an academic question -- which of these is faster:

    if (a == item1 || a == item2 || a == item3)

    or

    if ($items[item1, item2, item3] contains a)

    I would assume the first, but I like the compactness of the second. I would love to be surprised by the answer.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  5. #15
    Senior Member
    Join Date
    Jan 2010
    Posts
    692

    Default

    Thanks Veracity, that's very useful info and should probably be in the ASH Wiki. ... and many people don't even seem to realize ASH arrays exist.
    Originally Posted by zarqon View Post
    Indeed. I had assumed that split_string() was the only (and maybe other similar functions) way to get an array, and that creating one yourself was strictly out of the question and should be handled by using a map.

    Good to know.

  6. #16
    Developer jasonharper's Avatar
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    1,122

    Default

    This might be a good opportunity to ask an academic question -- which of these is faster:

    if (a == item1 || a == item2 || a == item3)

    or

    if ($items[item1, item2, item3] contains a)

    I would assume the first, but I like the compactness of the second. I would love to be surprised by the answer.
    Originally Posted by zarqon View Post
    This is going to depend on the number of items in the list, and which one happens to match; if 'a' is almost always item1, then the first form is likely to win on practical grounds, even though it's theoretically slower (O(n) vs. O(log n)).

    The second form is a definite win assuming no such coincidences of the item chosen, a somewhat larger set of items, and that the code is executed more than once per run of the script. The first lookup in a plural constant actually builds an internal map that allows such queries to be efficiently done; this is deferred because typical use of a plural constant involves only iteration, not lookups.

    There's always the "profile" command, if you really need to know which is more efficient in a given situation - although it's unlikely that either would have a noticeable effect on your script's performance.
    In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)

  7. #17
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,623

    Default

    Thanks Jason -- again, very useful info.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  8. #18
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,287

    Default

    That was a very interesting and useful answer. Thank you for asking it zarqon, and thanks for answering it Jason.
    If people like my scripts, please send me stuffed Hodgmen.
    Universal Recovery, OCD Inventory Control, CounterChecker, newLife, ChIT.


Similar Threads

  1. Replies: 0
    Last Post: 07-21-2014, 08:03 PM
  2. Replies: 0
    Last Post: 10-07-2012, 11:02 AM
  3. Replies: 0
    Last Post: 02-22-2011, 04:21 PM
  4. 8877: Add modifer: Combat Mana Cost
    By RSS Bot in forum Latest SVN Changes
    Replies: 3
    Last Post: 01-05-2011, 08:48 PM
  5. Replies: 9
    Last Post: 01-01-2010, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •