Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add an element to the beginning of a list #97

Open
michail-prusakov opened this issue Oct 17, 2012 · 1 comment
Open

Unable to add an element to the beginning of a list #97

michail-prusakov opened this issue Oct 17, 2012 · 1 comment

Comments

@michail-prusakov
Copy link

Consider the following unit test:

import java.util.List;

import org.apache.jdbm.DB;
import org.apache.jdbm.DBMaker;
import org.junit.Test;

public class JDBMTester {

@Test
public void testAddValueToHead() {
    DB db = DBMaker.openFile("tmp2").make();
    List<String> list = getList(db, "list2");
    list.add(0, "1");
    db.commit();
    db.close();
    db = DBMaker.openFile("tmp2").make();
    list = getList(db, "list2");
    list.add(0, "0");
    db.commit();
    db.close();
}

private <K> List<K> getList(DB db, String name) {
    List<K> result = db.getLinkedList(name);
    if (result == null) {
        result = db.createLinkedList(name);
    }
    return result;
}

}

@filipperich
Copy link

When adding to the front of the list, need to update the Root's pointer to first. Need to change LinkedList2.java:

421: Root r = getRoot();
422: r.size++;
423: db.update(rootRecid, r, ROOT_SERIALIZER);

421: Root r = getRoot();
ADD: if (prev == 0) r.first = recid;
422: r.size++;
423: db.update(rootRecid, r, ROOT_SERIALIZER);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants