All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pingbu.search.TextIndex Maven / Gradle / Ivy

The newest version!
package pingbu.search;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 文本搜索索引
 *
 * @author pingbu
 */
public class TextIndex implements SearchIndex {

    private final Map mIdToValues = new HashMap<>();
    private final Map> mValueToIds = new HashMap>();

    @Override
    public void addItem(final int id, final String value) {
        mIdToValues.put(id, value);
        List ids = mValueToIds.get(value);
        if (ids == null) {
            ids = new ArrayList<>();
            mValueToIds.put(value, ids);
        }
        ids.add(id);
    }

    @Override
    public ListIterator iterate(final String value) {
        return new ListIterator(mValueToIds.get(value));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy