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

org.biscuitsec.biscuit.datalog.TemporarySymbolTable Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package org.biscuitsec.biscuit.datalog;

import io.vavr.control.Option;

import java.util.ArrayList;
import java.util.List;

import static org.biscuitsec.biscuit.datalog.SymbolTable.DEFAULT_SYMBOLS_OFFSET;

public class TemporarySymbolTable {
    SymbolTable base;
    int offset;
    List symbols;

    public TemporarySymbolTable(SymbolTable base) {
        this.offset = DEFAULT_SYMBOLS_OFFSET + base.currentOffset();
        this.base = base;
        this.symbols = new ArrayList<>();
    }

    public Option get_s(int i) {
        if (i >= this.offset) {
            if (i - this.offset < this.symbols.size()) {
                return Option.some(this.symbols.get(i - this.offset));
            } else {
                return Option.none();
            }
        } else {
            return this.base.get_s(i);
        }
    }

    public long insert(final String symbol) {
        Option opt = this.base.get(symbol);
        if (opt.isDefined()) {
            return opt.get();
        }

        int index = this.symbols.indexOf(symbol);
        if (index != -1) {
            return (long) (this.offset + index);
        }
        this.symbols.add(symbol);
        return this.symbols.size() - 1 + this.offset;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy