Intrusive list implementation Java?

Is there a double linked list class that can be used for any (well implemented) intrusion of Java? Or should I be my own? Boost voltage C: http://beta.boost.org/doc/libs/1_40_0/doc/html/boost/intrusive/list.html.

An intrusive list is a prev pointer in a container (in this case) and element, so typical list operations (such as replace and remove) can be directly located to the base class rather than the container class In some cases, intrusive lists are the best solution

I try to give a proper example Let's assume that I have linked lists L LIST1 and l List2 owned by different types of classes X1 and Y2

Class Q (which has no relationship or is not easy to access the interfaces of X1 and Y2) needs to do this. I) replace, II) delete element e. it always exists somewhere in LIST1 XOR List2, depending on the runtime state, but the information will not be stored directly anywhere

Using the intruder list Q, you can store the reference of the element to the member element E, and it always points to the correct location

Otherwise, you must choose one or the other of several significantly more complex solutions. – Packing class of element E and other methods to complete the operation I and II No,

Basically, the problem is still not about performance, but the complexity of the architecture This can also be understood as a shared object situation, in which the solution IL avoids the update needs of LX and Q on each client

Please note that I do not need to be compatible with other standard containers It is just a general intrusive implementation of LSIT, which is used to iterate, add, delete and find unknown element classes

thank you.

Solution

I don't know any existing implementations (no, I don't think ordinary Java collections are intrusive)

This may be because the only major advantage of this list in Java is that when you already have an element to delete (and there is no iterator at that location), you will quickly call remove () Elements that are not copied are not valid parameters in Java because the Java list implementation only handles references (and does not copy the entire object)

However, you can easily write a common list implementation by creating the necessary interface:

public interface IntrusiveListElement<E extends<IntrusiveListElement<E>> {
  public void setNext(E next);
  public E getNext();
  public void setPrev(E prev);
  public E getPrev();
}

public class IntrusiveList<E extends IntrusiveListElement<E>> implements List<E> {
  // implement your run-of-the-mill double-linked list here
}

Your element class might look like this:

public class MyBusinessElement implements IntrusiveListElement<MyBusinessElement> {
  private MyBusinessElement prev;
  private MyBusinessElement next;

  public void setNext(MyBusinessElement next) {
    this.next = next;
  }

      public MyBusinessElement getNext() {
    return next;
  }

  public void setPrev(MyBusinessElement prev) {
    this.prev = prev;
  }

  public MyBusinessElement getPrev() {
    return prev;
  }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>