TreeMap over Arrays

Have been working on my project which has a fairly large TreeMap<Point, Pixel> on it; it is often that subMap(Point, Point) would be called.
Then in the process of profiling my code, I decided to write an ArrayMap<K extends Comparable<K>, V> which basically uses ArrayList<K> and ArrayList<V> to implement SortedMap<K, V>, and in which I use Collections.binarySearch(List<K>, K) for operations like headMap(K), subMap(K, K) and tailMap(K).
I've looked up the way TreeMap is in theory and the implementation and it seems to suggest that both versions of SortedMap have the same complexity on many of the operations.
But then the fact that TreeMap is in java.util but not my ArrayMap seems to me that the former is better in some ways. If so, is there any reasons why this would be the case?
Thanks
Alex Lam S.L.

For queries, both implementations may have the same complexity, but the ArrayList implementation has the capability to be a little faster bacause fewer pointers need to be followed. However, the TreeMap will be much faster if you need to manipulate the map (i.e. add/remove key-value pairs). For example, what happens if you add a key that comes before all the other keys? The array impl will be forced to do a bunch of copying, the tree won't...

Similar Messages

  • Two unexpected Locals variables when iterating over array of containers​.

    Hi,
    I iterate over an array of containers. In the ForEach loop step variables format I have defined two variables; one is current offset, second one is current element.
    The loop works fine.
    However, during the debug process, I've spotted two new Locals variables called __ElementSibling0 (type: number) and __ForEachReleaser0 (type: obj. reference) created silently by TS as soon as I start iterating over my array. What are they?
    Do they exist because:
    I'm iterating over an array of containers, or
    I use  the _currentElement_Freq variable, or
    it always like that?
    Solved!
    Go to Solution.

    Those are used by the implementation of the For Each step. You can see them only because you have enabled the Show Hidden Properties setting.
    You can safely ignore their presence.

  • Looping over arrays?

    Hello,
    I have a report which gives monthly totals of peoples
    production which is categorized and totaled. I also need the
    categories to have a Year to Date total with a combined year to
    date total. Doing this with queries is easy, but has a huge effect
    on load time. I am new to arrays and curious if this would be the
    correct direction. Each person on the report has a reportOrder
    which is sequential to the order on the report. If i had year to
    date totals with the report order (YearToDateUser[1] ,
    YearToDateUser[2], YearToDateUser[3]), is there a way to loop thru
    to output in the same order? Is this the wrong way to skin this
    cat? Any ideas would be greatly appreciated.
    Thanks,
    Matt

    Silly me....That was simple.
    <cfloop from="1" to="#qryGetOrder.recordcount#"
    index="i">
    <td
    class="wt"><cfoutput>#ArraySum(yeartodatepersons
    )#</cfoutput></td>
    </cfloop>
    Sorry to bother you all.

  • How to work with Arrays (or Lists) in WebService responses?

    Good Evening!
    In a BPEL process I invoked a some Webservice which return me a list of persons. Like this:
    <response>
    <personList>
    <person>Person1</person>
    <person>Person2</person>
    <person>Person3</person>
    </persons>
    </respons>
    Now i need to do something with Every returned element (like to invoke another webservice with parameter "person" (so i need to invoke a webservice for a 3 times))
    How i can do this?
    In Assign element CopyRules i see only:
    response |_
    personList|_
    person
    Like a person is a simple element, not a list.
    Should i use a For Each Element? And what to do next?
    Thank you.

    http://download.oracle.com/docs/cd/E12483_01/integrate.1013/b28981/manipdoc.htm#BABCHBFB
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    http://oraclebpelindepth.blogspot.com/2008/09/arrays-in-bpel_21.html
    you indeed need for each and loop over every person element in
    in the loop you can do the invokes of the other service with the input-data of the corresponding person-element-data
    person[1]/name
    person[2]/name
    etc

  • [Error ORABPEL-10039]: invalid xpath expression  - array processing

    hi,
    I am trying to process multiple xml elements
    <assign name="setinsideattributes">
    <copy>
    <from expression="ora:getElement('Receive_1_Read_InputVariable','BILL','/ns2:BILL/ns2:CMS1500['bpws:getVariableData('iterator')']/ns2:HEADER/ns2:SSN')"/>
    <to variable="ssn"/>
    </copy>
    </assign>
    where iterator is a index variable .
    I am getting into this error .
    Error(48):
    [Error ORABPEL-10039]: invalid xpath expression
    [Description]: in line 48 of "D:\OraBPELPM_1\integration\jdev\jdev\mywork\may10-workspace\multixm-catch\multixm-catch.bpel", xpath expression "ora:getElement('Receive_1_Read_InputVariable','BILL','/ns2:BILL/ns2:CMS1500['bpws:getVariableData('iterator')']/ns2:HEADER/ns2:SSN')" specified in <from> is not valid, because XPath query syntax error.
    Syntax error while parsing xpath expression "ora:getElement('Receive_1_Read_InputVariable','BILL','/ns2:BILL/ns2:CMS1500['bpws:getVariableData('iterator')']/ns2:HEADER/ns2:SSN')", at position "77" the exception is Expected: ).
    Please verify the xpath query "ora:getElement('Receive_1_Read_InputVariable','BILL','/ns2:BILL/ns2:CMS1500['bpws:getVariableData('iterator')']/ns2:HEADER/ns2:SSN')" which is defined in BPEL process.
    [Potential fix]: Please make sure the expression is valid.
    any information on how to fix this .
    thanks in advance

    check out this note here
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    hth clemens

  • How to use the arrays in BPEL

    I am giving the input below shows
    <to>
    <email>[email protected]</email>
    <email>[email protected]</email>
    </to>
    i will put the while loop and i count the index values.
    in while loop,it takes only one email id.
    my coding is
    <while condilition=('varindex'<ora:countnodes('inputvariable','payload',/client:to))>
    <assign activity>
    <first copy rule>
    <vartemp= concat('vartemp',"",bpws:getvariabledata('email'))>
    <second copy rule>
    <varindex = vraindex+1>
    </assign>
    </while>
    but vartemp adds only 1st email id.if i pass <vartemp= concat('vartemp',"",bpws:getvariabledata('email[varindex]'))> ,It shows error.
    pls how to retrieve the two email ids using array index.
    Edited by: user8984400 on Jan 13, 2010 11:22 PM

    have you tried this :
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    or this :
    http://oraclebpelindepth.blogspot.com/2008/09/arrays-in-bpel_21.html
    your assign should be something like :
    before this assign outside the loop you can assign the counter_index to some variable by ora:countnodes('inputvariable','payload',/client:to), and use this variable in the other xpaths
    <from expression="concat('/ns1:to/ns2:mail[',bpws:getVariableData('Variable_Index_Counter'),']') "/>
    <to variable="Variable_Xpath"/>
    notice also the [] characters, you need those together with the index-value to be able to loop over the list of email-elements
    hope its clear?

  • Read words from a text file into an undefined array

    Dear all,
    Does anyone know how to read words in text file, seperated by all types of spaces ("_", "\n", "\t","\r","\f") and put them into a string array to be used later?
    So far I can read the words using the Tokenizer but can't assign to array:
    public class reader
    StringTokenizer tokenizer = new StringTokenizer(input);
    String[ ] array= null;  //unknown size of array
    int i=0;
                   while(tokenizer.hasMoreTokens())
                             array[i] = tokenizer.nextToken();
                             i++;
    Any suggestions welcome!
    thanks in advance!

    Hi
    sorry wrote in a hurry ;) din c the problem clearly
    there are two approaches
    1) best approach for your problem is Vector or ArrayList, these would make life easy for you.
    Always collections are better approach over arrays when the size is dynamic. However in your case the size cant be said to be DYNAMIC. coz the number of words will not grow / shrink during the runtime.. i know that number of words are not fixed but dynamic is something which will grow/shrink during runtime. but still collection is better approach.
    2)dirty approach
    use double dimensional array
    String arr[][] = null;
    then use one tokenizer for StringTokenizer(str,"\n");
    using countTokens on this will give you number of lines.
    use this to initialize array
    arr = new String[lineCount][];
    then iterate from 1 to lineCount and use 1 more tokenizer to get number of words for that line. use this number to initialize the column size for arr[i] like
    arr[i] = new String[wordCount];
    then store the token using nested for loops in this array
    go for the 1st one ;) 2nd one is hedious n time consuming but both will work ;)
    cheers
    amey

  • JSON arrays vs. properties

    I'm finding that a JSON response from Raylight may or may not be an array depending on whether there are multiple items.  For example, a WebI doc with multiple reports will produce this:
      "reports": {
        "report": [
            "id": 2,
            "name": "Report 1",
            "reference": "2.RS",
            "showDataChanges": false
            "id": 1,
            "name": "Report 2",
            "reference": "1.RS",
            "showDataChanges": false
    Whereas if there is only one report tab, the result is:
      "reports": {
        "report":  {
            "id": 2,
            "name": "Report 1",
            "reference": "2.RS",
            "showDataChanges": false
    This is a problem, since the report property must be accessed differently.  With JQuery, if "report" is an array, I can access the individual reports with:
    $.each(json.reports.report,function() { $(this).id });
    But the code doesn't work if there is only one report -- it returns the properties of the "report" property instead of report itself.  Instead, I have to do:
    json.reports.report.id
    So, is there any code that can access the "report" properties whether or not it's an array?

    When we have arrays in java, why did they provide
    arraylist? What is the basic advantage of ArrayList
    over Array?
    Thanks in advanceLook at the API that would answer your question. All the functionality available for Arraylist is it available for arrays as well.
    It is very similar to asking why have String class when you can have an array of chars.
    Sun is just trying to make your life easy

  • Array Copy Problem

    ARRAY COPY DOESN'T WORK. DO NOT ATTEMPT TO USE IT IN YOUR REPLY TO THIS TOPIC. array copy says that you need the same type of object in the arrays. I'm making a method in a class called SUPERARRAYUTIL where this isn't the case. They all extend from a class i made called SUPERARRAY (in javacase caps tho, i just like to use upper case), but that doesnt help me. I'm short on time and i want to post this right now, so i won have any code right away but here is how i'm gonna do it:
    1) Static method takes parameters superArray array, superArray newelements, and int start
    2) Make a temp array that would be big enough to fit array, and the newelements at postion start in array
    3) copy over array using a for loop, starting at 0 in temp.
    4) copy over newelements using a for loop, starting at start in temp.
    Then i will make non-static methods for superArrayUtil that will use the static methods in superArrayUtil. I will also make a method like System.arraycopy but will call a method called cut to trim the array of new elements and then call this arraycopy to copy it into the dest array, and then another non-static method for that method too.
    Basically i just need ideas or comments cause so far i ran into some weird problems or any suggestions if there's a better way to copy arrays in the general way of array1 into array2 at a starting position.

    Deo_Favente wrote:
    ARRAY COPY DOESN'T WORK.
    YES. YES IT DOES. WHY DO YOU THINK THAT IT DOESNT WORK? WHY DON'T YOU POST WHATEVER CODE THAT YOU DO HAVE THAT IS CAUSING YOU PROBLEMS AND THEN MAYBE WE COULD WORK WITH IT. I THINK THAT'S A BETTER IDEA PERSONALLY, AT LEAST OPPOSED TO WHAT YOU DID HERE._+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Arrays vs ArrayList

    When we have arrays in java, why did they provide arraylist? What is the basic advantage of ArrayList over Array?
    Thanks in advance

    When we have arrays in java, why did they provide
    arraylist? What is the basic advantage of ArrayList
    over Array?
    Thanks in advanceLook at the API that would answer your question. All the functionality available for Arraylist is it available for arrays as well.
    It is very similar to asking why have String class when you can have an array of chars.
    Sun is just trying to make your life easy

  • AS2 CS4 iterating through an array?

    Alright so i've had this problem for far too long here and i need help. first of all here's the code
    and if you can tell me how i can put it in more or less of a "code box" that makes it easier to read by including the indents, it would be also appreciated.
    function(){return A.apply(null,[this].concat($A(arguments)))}
    function(){return A.apply(null,[this].concat($A(arguments)))}class controller extends MovieClip
    function NewBox()
      if(number < 50)
       timer = 0
       number +=1
       var box = _root.contentMain.attachMovie("name1", "name0"+number, number)
       box._y = position
       boxes.push(box)
       trace(boxes)
       if(position > 120)
        var position1 = -1*position + 40
        _root.contentMain._y = position1
        if(_root.contentMain._y < -740){_root.contentMain._y = -740}
        if(_root.contentMain._y > -740){_root.scrollFace._y += 1.85}
    function hilite()
      if(prob > 0)
       timer = 0
       var work2 = _root.contentMain.attachMovie("highliter", "highliter", number + chronos)
       work2._y = Math.floor(Math.random()*number)*17.4+ 17.4
       _root.contentMain._y = -1*work2._y + 20
      if(prob < 0)
       timer = 0
       var work1 = _root.contentMain.attachMovie("controller2","controller2",number+chronos+1)
       var work2 = _root.contentMain.attachMovie("highliter", "highliter", number+chronos)
       work1._x = -200
       work1._y = Math.floor(Math.random()*number)*17.4+ 17.4
       work2._y = work1._y
       _root.contentMain._y = -1*work1._y + 20
       controllers.push(work1)
       hiliters.push(work2)
    function MinusBox()
      if(number > 1)
       removeMovieClip(_root.contentMain.name0+number)
       number -= 1
    function(){return A.apply(null,[this].concat($A(arguments)))}
    function(){return A.apply(null,[this].concat($A(arguments)))}class highliter extends MovieClip
    var timer1
    function onLoad()
      timer1 = 0
    function onEnterFrame()
      timer1 += 1
      if(timer1 > 72)
       timer1 = 0
       this.removeMovieClip()
      for(var i in _root.contentMain.controller1.controllers)
       if(this.hitTest(_root.contentMain.controller1.controllers[i]))
        this.removeMovieClip()
        _root.contentMain.controller1.hilite()
    now here's one problem, it only checks collisions for the first object in the array "controllers", and no others. and i want it to check for all objects
    and second of all, how can i refer to an object whose instance name includes a variable as seen in "function MinusBox"
    many many thanks for any help to my annoying problems.

    this is how I do it, I construct the expression outside .. bpws:getVariableData will probably not execute xpath/
    <pre><code>
    <assign name="prepare_loop">
    <copy>
    <from expression="number(1)"/>
    <to variable="i"/>
    </copy>
    <copy>
    <from expression="ora:countNodes('EmpQuerySelect_p_deptno_OutputVariable','EmpCollection','/ns2:EmpCollection/Emp')"/>
    <to variable="n"/>
    </copy>
    </assign>
    <while name="While_1" condition="bpws:getVariableData('i') <= bpws:getVariableData('n')">
    <scope name="Scope_1">
    <variables>
    <variable name="selector" type="ns3:string"/>
    <variable name="element" element="ns2:Emp"/>
    </variables>
    <sequence name="Sequence_1">
    <assign name="Get_Element">
    <copy>
    <from expression="concat("/ns2:EmpCollection/Emp[",string(bpws:getVariableData('i')),"]")"/>
    <to variable="selector"/>
    </copy>
    <copy>
    <from expression="bpws:getVariableData('EmpQuerySelect_p_deptno_OutputVariable','EmpCollection',bpws:getVariableData('selector'))"/>
    <to variable="element" query="/ns2:Emp"/>
    </copy>
    </assign>
    <empty name="Do_stuff_with_element_Var"/>
    <assign name="Increment_index">
    <copy>
    <from expression="bpws:getVariableData('i')+1"/>
    <to variable="i"/>
    </copy>
    </assign>
    </sequence>
    </scope>
    </while>
    </code></pre>
    btw
    i have deicated an article on my blog on this subject.
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    hth clemens
    Message was edited by:
    clemens.utschig

  • Odd & even array

    Hi, can someone please tell me why this is not working? I am supposed to have a user input numbers into an array. If the numbers are even they go into the even ArrayList and for odd, vice versa.public static void main(String[] args)
             int num,xy=0, MAX = 10;
             int [] numbers = new int [MAX];
             EasyReader console = new EasyReader();
             ArrayList evenNumbers = new ArrayList();
             ArrayList oddNumbers = new ArrayList();
             for (num=0; num<=MAX; num++)
                    System.out.println("Please enter a number to put into the array: ");
                  numbers[num]=console.readInt();
             for (int x=0; x<=MAX; x++)
                  Integer some= new Integer(numbers[x]);
                  if((numbers[num]%2)==0)
                       evenNumbers.add(new Integer(x));
                  else
                       oddNumbers.add(new Integer(x));
             for (int i=0; i<numbers.length; i++)
                  System.out.println("The array is:" +numbers);
         for (int i=0; i<oddNumbers.size(); i++)
              System.out.println("The odd arrayList is: "+oddNumbers.get(i));
         for (int i=0; i<evenNumbers.size(); i++)
              System.out.println("The even arrayList is: "+evenNumbers.get(i));
    Thanks.

    By "exception 11" I think you mean an ArrayIndexOutOfBoundsException.
    Take a look at these lines:
    int num, MAX = 10;
    int [] numbers = new int [MAX];
    for (num=0; num<=MAX; num++) {
        numbers[num]=...
    }If array numbers has 10 elements they are stored in numbers[0] to numbers[9] -- there is no numbers[MAX]. So loops that iterate over arrays should be written:
    for (int num=0; num<numbers.length; num++) {You did that further down in the code, too.
    something seems off???

  • How to retrieve the email array

    How to retrieve the two emails in Bpel

    have you tried this :
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    or this :
    http://oraclebpelindepth.blogspot.com/2008/09/arrays-in-bpel_21.html
    your assign should be something like :
    before this assign outside the loop you can assign the counter_index to some variable by ora:countnodes('inputvariable','payload',/client:to), and use this variable in the other xpaths
    <from expression="concat('/ns1:to/ns2:mail[',bpws:getVariableData('Variable_Index_Counter'),']') "/>
    <to variable="Variable_Xpath"/>
    notice also the [] characters, you need those together with the index-value to be able to loop over the list of email-elements
    hope its clear?

  • Arrays vs arraylists

    How do you guys determine whether to use arrays or the arrayList? I've seen situations where arrays are used that I thought arrayLists were more fitting. Is there some kind of performance penalty when using arrayLists over arrays?
    Thanks in advance!

    Array are more efficient rispect to ArrayList, but the dimension of an array can be decided only once:
    Array a = new Array[20] \\ this array will never contain 21 elements
    ArrayList are dinamically reallocated each time you add a new element
    Another thingh is thata when you istance a Array variable you will immediatly reserve a portion of memory for all the elements of the array
    When you istance a ArrayList variable you only create the variable but there will be memory allocation only for the inserted elements
    So:
    If you know in advance the max number of elements of the array probably you need an Array
    If you know the max number of element, this number if very hight, and you know that the max part of the program there will be very less element you probably will choose ArrayList to use less memory
    If you totally dont know how many elemnts you have to manipulate you have to chose an ArrayList.
    Hope it's enought (and not Wrong)
    Riccardo Coletta

  • How to Dynamically construct the conditional IF statement in java

    Is there a way to dynamically construct a conditional IF statement in java?
    For example:
    Suppose i have a 2D array like:
    Array[the actual values to search for][the column number in the table to perform the search on].
    e.g.
    Array {
                 {"x"} , {1},  
                 {"y"} , {2},  
                 {"z"} , {3},  
    }How can i construct the if statement like:
    Looping over table rows (tableRow) {
        Looping over array {
            IF ( {"x"}. equals( tableModel.getValueAt( tableRow, {1})   &&
                   {"y"}. equals( tableModel.getValueAt( tableRow, {2})   &&
                   {"z"}. equals( tableModel.getValueAt( tableRow, {3})  )              
            return true;
    }The array can grow or shrink based on the values in it so therefore IF statement will grow or shrink. How can i achieve it?
    If not then how can i achieve this?

    My understanding (feeble at best) is that a sieries of && elements will be evaluated in order until the first false value is encountered. So, in an "if a && b && c" statement where b is false c will never be evaluated and the conditional executable will not run. Is that what you mean?
    Yes, logical expressions will not evaluate unnecessary operands. So you can safely write the following, for instance, without getting an error,
    if ((anArray != null) && (anArray.length > 0)) { ... }because the second operand of the '&&' will never be evaluated if 'anArray' is null.
    Also, is there a difference between & and &&?
    & is a bitwise operator, && is a boolean operator.

Maybe you are looking for

  • Forcing a Commit() to LMS

    We're experiencing issues with our captivate coureses in Oracle LMS.  I'm trying to used execute a javascript to force the course to send a commit to the LMS more often. I've tried doing this through a button that would execute g_objAPI.LMSCommit('')

  • Send Separate Remittance Advices in R12 Customization

    How to add the new XML tag in Send Separate Remittance Advices in R12 which is java concurrent program. What is the approach to add the new XML tag using standard Send Separate Remittance Advices in R12 and the new tag will use in my .rtf ( template

  • Slow reply with typing and cursor, FF 30, Windows 7...help?

    I am getting a delay every time I type in a field as well as when scrolling. Every input is delayed. I can type a few words, scroll half a page and then everything freezes. I see that this is a common problem but no solution. I have no problem with C

  • Port event mechanism and full dupex socket -AIO with Completion Port

    Hi, I just started to port code from Windows OS to Solaris. I need a way to implement something similar to AIO with Completion Port from Windows on Solaris OS. After initial investigation I have discovered port - events API. It is quite elegant. The

  • Can anyone tell me the price of iphone4s unlocked in US ?

    can anyone tell me d price of iphone 4s unlocked in US