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

io.github.shanqiang.table.Index Maven / Gradle / Ivy

The newest version!
package io.github.shanqiang.table;

import io.github.shanqiang.offheap.ByteArray;

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

public class Index {
    private final Map, List> columns2Rows;

    public Index() {
        columns2Rows = new HashMap<>();
    }

    public void put(List columns, int row) {
        List rows = columns2Rows.get(columns);
        if (null == rows) {
            columns2Rows.put(columns, new ArrayList(1){{
                add(row);
            }});
        } else {
            rows.add(row);
        }
    }

    public Map, List> getColumns2Rows() {
        return columns2Rows;
    }

    public List get(List key) {
        return columns2Rows.get(key);
    }

    public List get(Comparable[] key) {
        List keyList = new ArrayList<>(key.length);
        for (Comparable elem : key) {
            if (elem instanceof String) {
                keyList.add(new ByteArray((String) elem));
            } else {
                keyList.add(elem);
            }
        }
        return columns2Rows.get(keyList);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy