Iterating over LinkedHashMap (doubly-linked) backwards

I have a complete lack of understanding here. I interpret "doubly-linked" to mean every node has a pointer to the next node plus a pointer to the previous node. I don't see a way to get an Iterator that goes from the tail to the head of a LinkedHashMap, however.
How do I iterate backwards over a LinkedHashMap?
If I have to use some external object to reverse the order of the keys, what is the point of doubly-linking the list?
Thanks for any help.

pbyhistorian wrote:
I have a complete lack of understanding here. I interpret "doubly-linked" to mean every node has a pointer to the next node plus a pointer to the previous node. Yes, but that's an implementation detail that you as a user don't need to know about to use the features of the data structure. (It does come into play where performance is concerned.)
I don't see a way to get an Iterator that goes from the tail to the head of a LinkedHashMap, however.If it's not in the docs, then it doesn't have one.
Note that it would be possible to iterate backwards even without such an internal implementation detail. And even if such an implementation detail is there, that doesn't mean it will be exposed in the public interface.
How do I iterate backwards over a LinkedHashMap?If there's no method provided, you don't.
If I have to use some external object to reverse the order of the keys, what is the point of doubly-linking the list?It may still be useful for the implementations of some of the methods, even if it's not directly exposed to the user.

Similar Messages

  • Any performance overhead if we get iterator over values stored in map

    Hi Everybody,
    Is there any performance overhead if we get iterator over values stored in map. like this
    Iterator itr = rolesMap.values().iterator();
    if yes please explain...thanks in advance.

    ejp wrote:
    That's rather out of date. It is how Hashtable works, but as regards HashMap it isn't. The keySet() iterator and the values() iterator are both written in terms of the entrySet() iterator. There is no skipping over unused slots.Out of date? In that case there's been a recent advance in hashed data structures I've missed.
    Or the HashMap implementation has been recently changed to internally link entries to improve iteration performance. I doubt that because such a list would degrade the performance of the HashMap in other ways and that's unacceptable (and unnecessary because of LinkedHashMap).
    Besides, what I said is in the Java 6 API documentation to LinkedHashMap. It may be out of date but I doubt it.
    So here we are with a fact of nature: Any iteration of a hash based data structure will be proportional to capacity rather than the number of entries, unless a supportive list style data structure is introduced to overcome this.

  • Travwerse a linked list in a doubly linked list

    I have to traverse a linked list to a doubly linked list and I am not sure how to do that.
    Here is some sample code:
    class linkData {
              dataRecord data;
              linkData next;
              linkData prev;
    linkData head;Should I use something like this:
    if (index < (size >> 1)) {
                     next = header.next;
                     for (nextIndex=0; nextIndex<index; nextIndex++)
                       next = next.next;
                 } else {
                    next = header;
                     for (nextIndex=size; nextIndex>index; nextIndex--)
                         next = next.previous;
                 }

    mindspeed wrote:
    I have to traverse a linked list to a doubly linked list This makes no sense as traverse means to pass or move over or along something. Perhaps you mean translate instead.

  • OSB - Iterating over large XML files with content streaming

    Hi @ll
    I have to iterate over all item in large XML files and insert into a oracle database.
    The file is about 200 MB and contains around 500'000, and I am using OSB 10gR3.
    The XML structure is something like this:
    <allItems>
    <item>.....</item>
    <item>.....</item>
    <item>.....</item>
    <item>.....</item>
    <item>.....</item>
    </allItems>
    Actually I thought about using a proxy service with enabled content streaming and a "for each" action for iterating
    over all items. But for this the whole XML structure has to be materialized into a variable otherwise it is not possible!
    More about streaming large files can be found here:
    [http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#large_messages]
    There is written "When you enable streaming for large message processing, you cannot use the ... for each...".
    And for accessing single items you should should use an assign action with a xpath like "$body/allItems/item[1]";
    this works fine and not the whole XML stream has to be materialized.
    So my idea was to use the "for each" action and processing seqeuntially all items with a xpath like:
    $body/allItems/item[$counter]
    But the "for each" action just allows iterating over a sequence of xml items by defining an selection xpath
    and the variable that contains all items. I would like to have a "repeat until" construct that iterates as long
    $body/allItems/item[$counter] returns not null. Or can I use the "for each" action differently?
    Does the OSB provides any other iterating mechanism? I know there is this spli-join construct that supports
    different looping techniques, but as far I know it does not support content streaming, is this correct?
    Did I miss somehting?
    Thanks a lot for helping!
    Cheers
    Dani
    Edited by: user10095731 on 29.07.2009 06:41

    Hi Dani,
    Yes, according to me this would be the best approach. You can use content-streaming to pass this large xml to ejb and once it passes successfully EJB should operate on this. If you want any result back (for further routing), you can get it back from EJB.
    EJB gives you power of java to process this file and from java perspective 150 MB is not a very LARGE data. Ensure that you are using buffering. Check out this link for an explanation on Java IO Streams and, in particular, buffered streams -
    http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
    Try dom4J with xpp (XML Pull Parser) parser in case you have parsing requirement. We had worked with 1.2GB file using this technique.
    Regards,
    Anuj

  • Not to hard for you java types.  Simply creating a doubly linked list.

    How do i go about declaring a doubly linked list and add nodes to it?

    see http://java.sun.com/j2se/1.3/docs/api/java/util/LinkedList.html
    which is implemented as a doubly linked list:
    import java.util.*;
    public class ListTest {
      public static void main(String [] argv) {
        // synchronize if multiple threads are using list
        LinkedList list = Collections.synchronizedList(
          new LinkedList());
        list.addFirst("this");
        list.addLast("is");
        list.addLast("a test");
        ListIterator it = list.iterator(0);
        // with iterator you can walk the list
    }You can then use iterators to walk the list:
    http://java.sun.com/j2se/1.3/docs/api/java/util/ListIterator.html
    Good Luck.

  • Why LinkedList uses doubly linked list and not single link list

    Hi,
    Please help me to understand the concept behind java using doubly linked list for LinkedList and not single link list?
    Edited by: user4933866 on Jun 26, 2012 11:22 AM
    Edited by: user4933866 on Jun 26, 2012 11:25 AM
    Edited by: EJP on 27/06/2012 08:50: corrected title to agree with question

    EJP wrote:
    Could you help me with one real world use case where we need to traverse linklist and arraylist in backward direction other than printing the linklist or arraylist in reverse order. One example is that you might want to use it as a stack. For a very large (+very+ large) stack it would out-perform the Vector-based Stack in the API.The first thing that pops into my head is an undo/redo function for a text editor. Each edit action is dumped onto such a stack. Each time you hit CTRL+Z to undo an action you go back in the stack. Each time you hit CTRL+Y to redo the action you go forward again.

  • What is the best way to submit a Concurrent Request over a DB Link?

    Hi,
    We have a requirement to submit a Concurrent Request over a DB Link. What is the best way to do this?
    What I've done so far is I've created a function in the EBS instance that executes FND_GLOBAl.APPS_INITIALIZE and submits the Concurrent Request. I then call this function remotely from our NON-EBS database. It seems to work fine but I found out from metalink article id 466800.1 that this is not recommended.
    Why are Concurrent Programs Calling FND_GLOBAL.APPS_INITIALIZE Using DBLinks Failing? [ID 466800.1]
    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_afrLoop=11129815723825&type=DOCUMENT&id=466800.1&displayIndex=1&_afrWindowMode=0&_adf.ctrl-state=17dodl8lyp_108
    Can anyone suggest a better approach?
    Thanks,
    Allen

    What I've done so far is I've created a function in the EBS instance that executes FND_GLOBAl.APPS_INITIALIZE and submits the Concurrent Request. I then call this function remotely from our NON-EBS database. It seems to work fine but I found out from metalink article id 466800.1 that this is not recommended.
    Why are Concurrent Programs Calling FND_GLOBAL.APPS_INITIALIZE Using DBLinks Failing? [ID 466800.1]
    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_afrLoop=11129815723825&type=DOCUMENT&id=466800.1&displayIndex=1&_afrWindowMode=0&_adf.ctrl-state=17dodl8lyp_108
    Can anyone suggest a better approach?Please log a SR and ask Oracle support for any better (alternative) approach. You can mention in the SR that your approach works properly and ask what would be the implications of using it (even though it is not recommended).
    Thanks,
    Hussein

  • How do I find the smallest element of a doubly linked list?

    I currently have a doubly link list, each node contains two datafields df1 and df2. I need to find the smallest of df2 contained in the list and swap it with index one - until the list is sorted.
    Any ideas on how to search a doubly linked list for the smallest element would be greatly appreciated, thanks for your help.
    ps: I have found methods for find an element in a list and tried to alter it to find smallest, but my dfs are objects and I am having difficulty with the comparison.
    thanks so much for your time.

    I have given some comments in your other thread and instead of finding the minimum in each scan, you can do "neighbour-swaps". This will sort the list in fewer scans.

  • Insert, update and delete trigger over multiple Database Links

    Hello guys,
    first of all I'll explain my environment.
    I've got a Master DB and n Slave Databases. Insert, update and delete is only possible on the master DB (in my opinion this was the best way to avoid Data-inconsistencies due to locking problems) and should be passed to slave databases with a trigger. All Slave Databases are attached with DBLinks. And, additional to this things, I'd like to create a job that merges the Master DB into all Slave DB's every x minutes to restore consistency if any Error (eg Network crash) occurs.
    What I want to do now, is to iterate over all DB-Links in my trigger, and issue the insert/update/delete for all attached databases.
    This is possible with the command "execute immediate", but requires me to create textual strings with textually coded field values for the above mentioned commands.
    What I would like to know now, is, if there are any better ways to provide these functions. Important to me is, that all DB-Links are read dynamically from a table and that I don't have to do unnecessary string generations, and maybe affect the performance.
    I'm thankful for every Idea.
    Thank you in advance,
    best regards
    Christoph

    Well, I've been using mysql for a long time, yes, but I thought that this approach would be the best for my requirements.
    Materialized View's don't work for me, because I need real-time updates of the Slaves.
    So, sorry for asking that general, but what would be the best technology for the following problem:
    I've got n globally spread Systems. Each of it can update records in the Database. The easies way would be to provide one central DB, but that doesn't work for me, because when the WAN Connection fails, the System isn't available any longer. So I need to provide core information locally at every System (connected via LAN).
    Very important to me is, that Data remain consistent. That means, that it must not be that 2 systems update the same record on 2 different databases at the same time.
    I hope you understand what I'd need.
    Thank you very much for all your replies.
    best regards
    Christoph
    PS: I forgot to mention that the Databases won't be very large, just about 20k records, and about 10 queriees per second during peak times and there's just the need to sync 1 Table.
    Edited by: 907142 on 10.01.2012 23:14

  • Sorting a doubly linked list

    Hello people!
    I have problems with sorting a doubly linked list, I have kind of got stuck just looking at the code and don't really know what I'm doing anymore...
    public void sortList()
    int flag = 0;
    DoubleNode temp; //Doubly Linked List Node
    temp = firstNode;
    String tempData;
    while (flag != 1)
    flag = 1;
    String data = (String)temp.element;
    while (temp.next != null)
    int comp = data.compareTo((String)temp.next.element);
    if (comp > 0)
    tempData = (String)temp.element;
    temp.element = temp.next.element;
    data = (String)temp.element;
    temp.next.element = tempData;
    flag = 0;
    else
    temp = temp.next;
    data = (String)temp.element;
    I'm trying to take an easy way around the problem by not swaping nodes but just the data the nodes contain. I'm pretty new to this and my prof. has just gone insane giving us this hardcore assignment.
    is this code even close to be correct?
    is this a good way of tackling the problem?
    thanks a lot! / Dan

    Okay, without going into any great detail about possible issues with the algorithm or code, it's gonna first be necessary to know some more about the DoubleNode class. For example, does it have a next method? If it does, then right off the bat your code will have to be adjusted so that where you have written "temp.next" you actually call the next method (which, if it is parameterless, would be "temp.next()"). As you have it written now, "temp.next" is accessing the "next" attribute of your DoubleNode instance, and I don't think that's what you're intending.
    -dSn

  • Doubly Linked List

    I have a doubly linked list and I wrote two methods, one to insert items at a specified index and one method to remove items at a specified index. I am not 100% sure if I wrote these methods correctly. Well I'm pretty sure I messed something up because I'm having trouble implementing a swap method and I think this is where the problem lies.
       * @param o the object to insert.
       * @param i the index to add the object.
      public void insertAt(Object o, int i) {
        if (i==0) {
          prepend(o);
        else {
          int j= 0;
          Node previous= first;
          Node next= first;
          while (j<i) {
            previous= next;
            next= previous.getNext();
            j++;
          Node insertAt= new Node(o, previous, next);
          previous.setNext(insertAt);
          insertAt.setPrevious(previous);
          insertAt.setNext(next);
          next.setPrevious(insertAt);
        size++;
       * @param i the index of the object to remove.
      public Object removeAt(int i) {
        if (i==0) {
          removeFirst();
          return first.getData();
        else {
          int j= 0;
          Node previous= first;
          Node next= first;
          while (j<i) {
            previous= next;
            next= previous.getNext();
            j++;
          Node temp=next.getNext();
          if (temp.equals(null)) {
            previous.setNext(null);
            last= previous;
            return next.getData();
          previous.setNext(temp);
          temp.setPrevious(previous);
          return next.getData();
      }

    public Object removeAt(int i) {
    if (i==0) {
    removeFirst();
    return first.getData();
    }I can't be sure from the code but the above code looks like a problem: if you remove the node before you get the data, aren't you returning the data from the second node (now the first)?

  • How to test issue with accessing tables over a DB link?

    Hey all,
    Using 3.1.2 on XE, I have a little app. The database schema for this app only contains views to the actual tables, which happen to reside over a database link in a 10.1.0.5.0 DB.
    I ran across an issue where a filter I made on a form refused to work (see [this ApEx thread| http://forums.oracle.com/forums/message.jspa?messageID=3178959] ). I verified that the issue only happens when the view points to a table across a DB link by recreating the table in the local DB and pointing the view to it. When I do this, the filter works fine. When I change the view back to use the remote table, it fails. And it only fails in the filter -- every other report and every other tool accessing the remote table via the view works fine.
    Anyone know how I can troubleshoot this? For kicks, I also tried using a 10.2.0.3.0 DB for the remote link, but with the same results.
    TIA,
    Rich
    Edited by: socpres on Mar 2, 2009 3:44 PM
    Accidental save...

    ittichai wrote:
    Rich,
    I searched metalink for your issue. This may be a bug in 3.1 which will be fixed in 4.0. Please see Doc ID 740581.1 Database Link Tables Do NoT Show Up In Table Drop Down List In Apex. There is a workaround mentioned in the document.
    I'm not sure why I never thought of searching MetaLink, but thanks for the pointer! It doesn't match my circumstances, however. The Bug smells like a view not being queried in the APEX development tool itself -- i.e. the IDE's coding needs changing, not necessarily those apps created with the IDE.
    I'm working on getting you access to my hosted app...
    Thanks,
    Rich

  • TE over ospf virtual-link does not work

    Hi Expert,
    I want to practise the TE over ospf virtual-link. The topo is like this one:
    R1 R2
    | |
    R3---R4
    | |
    R5 R6
    all links are in area 0 except link between R3 and R4.
    rt5_1#ro
    router ospf 1
    router-id 1.1.1.1
    log-adjacency-changes
    network 0.0.0.0 255.255.255.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    interface Tunnel16
    ip unnumbered Loopback0
    tunnel destination 6.6.6.6
    tunnel mode mpls traffic-eng
    tunnel mpls traffic-eng autoroute announce
    tunnel mpls traffic-eng priority 5 5
    tunnel mpls traffic-eng bandwidth 5
    tunnel mpls traffic-eng path-option 10 dynamic
    rt5_2#ro
    router ospf 1
    router-id 2.2.2.2
    log-adjacency-changes
    network 0.0.0.0 255.255.255.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    rt5_3#ro
    router ospf 1
    router-id 3.3.3.3
    log-adjacency-changes
    area 1 virtual-link 4.4.4.4
    network 3.3.3.3 0.0.0.0 area 0
    network 10.10.13.0 0.0.0.255 area 0
    network 10.10.34.0 0.0.0.255 area 1
    network 10.10.35.0 0.0.0.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    mpls traffic-eng interface
    Ethernet1/0/1 area 0
    rt5_4#ro
    router ospf 1
    router-id 4.4.4.4
    log-adjacency-changes
    area 1 virtual-link 3.3.3.3
    network 4.4.4.4 0.0.0.0 area 0
    network 10.10.24.0 0.0.0.255 area 0
    network 10.10.34.0 0.0.0.255 area 1
    network 10.10.46.0 0.0.0.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    mpls traffic-eng interface Ethernet1/1 area 0
    rt5_5#ro
    router ospf 1
    router-id 5.5.5.5
    log-adjacency-changes
    network 5.5.5.5 0.0.0.0 area 0
    network 10.10.35.0 0.0.0.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    rt5_7#ro
    router ospf 1
    router-id 6.6.6.6
    log-adjacency-changes
    network 6.6.6.6 0.0.0.0 area 0
    network 10.10.46.0 0.0.0.255 area 0
    mpls traffic-eng router-id Loopback0
    mpls traffic-eng area 0
    The tunnel 16 on R1 from R6 does not come up .
    rt5_1#sh mpls traffic-eng tunnels t16
    Name: rt5_1_t16 (Tunnel16) Destination: 6.6.6.6
    Status:
    Admin: up Oper: down Path: not valid Signalling: Down
    path option 10, type dynamic
    Config Parameters:
    Bandwidth: 5 kbps (Global) Priority: 5 5 Affinity: 0x0/0xFFFF
    Metric Type: TE (default)
    AutoRoute: enabled LockDown: disabled Loadshare: 5 bw-based
    auto-bw: disabled
    Shortest Unconstrained Path Info:
    Path Weight: UNKNOWN
    Explicit Route: UNKNOWN
    History:
    Tunnel:
    Time since created: 1 hours, 7 minutes
    Path Option 10:
    Last Error: PCALC:: No path to destination, 6.6.6.6
    Does anyone the cause of the problem?
    thanks,

    Hi,
    There is one virutal link between R3 and R4.
    rt5_1#sh mpls traffic-eng topology
    IGP Id: 3.3.3.3, MPLS TE Id:3.3.3.3 Router Node (ospf 1 area 0)
    link[0]: Broadcast, DR: 10.10.35.5, nbr_node_id:24, gen:224
    frag_id 1, Intf Address:10.10.35.3
    TE metric:10, IGP metric:10, attribute flags:0x0
    link[1]: Broadcast, DR: 10.10.13.1, nbr_node_id:25, gen:224
    frag_id 0, Intf Address:10.10.13.3
    TE metric:10, IGP metric:10, attribute flags:0x0
    link[2]: Broadcast, DR: 10.10.34.3, nbr_node_id:-1, gen:224
    frag_id 3, Intf Address:10.10.34.3
    TE metric:10, IGP metric:invalid, attribute flags:0x0
    sh mpls traffic-eng topology brief
    IGP Id: 3.3.3.3, MPLS TE Id:3.3.3.3 Router Node (ospf 1 area 0)
    link[0]: Broadcast, DR: 10.10.35.5, nbr_node_id:31, gen:106
    frag_id 1, Intf Address:10.10.35.3
    TE metric:10, IGP metric:10, attribute flags:0x0
    link[1]: Broadcast, DR: 10.10.13.1, nbr_node_id:32, gen:106
    frag_id 0, Intf Address:10.10.13.3
    TE metric:10, IGP metric:10, attribute flags:0x0
    link[2]: Broadcast, DR: 10.10.34.3, nbr_node_id:-1, gen:106
    frag_id 3, Intf Address:10.10.34.3
    TE metric:10, IGP metric:invalid, attribute flags:0x0
    IGP Id: 4.4.4.4, MPLS TE Id:4.4.4.4 Router Node (ospf 1 area 0)
    link[0]: Broadcast, DR: 10.10.46.6, nbr_node_id:34, gen:104
    frag_id 0, Intf Address:10.10.46.4
    TE metric:10, IGP metric:invalid, attribute flags:0x0
    link[1]: Broadcast, DR: 10.10.24.2, nbr_node_id:19, gen:104
    frag_id 1, Intf Address:10.10.24.4
    TE metric:10, IGP metric:10, attribute flags:0x0
    link[2]: Broadcast, DR: 10.10.34.3, nbr_node_id:-1, gen:104
    frag_id 2, Intf Address:10.10.34.4
    TE metric:10, IGP metric:invalid, attribute flags:0x0
    IGP Id: 5.5.5.5, MPLS TE Id:5.5.5.5 Router Node (ospf 1 area 0)
    link[0]: Broadcast, DR: 10.10.35.5, nbr_node_id:31, gen:94
    thanks,
    guoming

  • 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.

  • [SOLVED] Iteration over a BPM Object.

    Hi guys, here i'm trying to solve a problem. May be simple, but i cant iterate over a BPM object without using the fuego taglibs.
    I need to iterate over the object X. The X object have one attribute, called itens, that is a group with values.
    In my JSP, using the code, works:
    <tr><td><b>Objeto.codigo:</b></td><td><f:fieldValue att="x.code" onlyValue="true"/></td></tr>
    <tr><td><b>Objeto.nome:</b></td><td><f:fieldValue att="x.name" onlyValue="true"/></td></tr>
    <tr><td><b>Objeto.item1:</b></td><td><f:fieldValue att="x.itens[0].description" onlyValue="true"/></td></tr>
    I have tried a conjuction with a <c:forEach> to iterate over the x.itens attribute without success, like this
    <c:forEach var="item" items="${x.itens}">
    ${item.description}
    </c:forEach>
    With JSP EL, there's a way to access this attribute without workarounds?
    Thanks!
    Thiago
    Edited by: user10128107 on 08/01/2009 04:04
    It was the use of the core taglib...
    Edited by: user10128107 on 08/01/2009 05:49

    madeqx wrote:
    Will this piece of code be significantly slower than iteration over an ArrayList?a) No. Iteration is O(n) in both cases.
    b) Irrelevant. If your design calls for a map, use a map, and if it calls for a list, use a list. The two serve entirely different purposes, and we don't choose between map and list for performance reasons.

Maybe you are looking for