import { Rule } from "../../grammar/rule" ; import { State } from "./state" ; import { StateToObjectMap } from "./state-to-object-map" ; export class StateIndex < SemiringType , TokenType > { private states : StateToObjectMap < TokenType , State < SemiringType , TokenType > > ; constructor ( ) { this . states = new StateToObjectMap < TokenType , State < SemiringType , TokenType > > ( ) ; } public addState ( state ) { if ( this . states . hasByState ( state ) ) throw new Error ( "State set already contained chart. This is a bug." ) ; else this . states . putByState ( state , state ) ; } public getState ( rule , index , ruleStart , ruleDot ) { if ( ! this . states . has ( rule , index , ruleStart , ruleDot ) ) throw new Error ( "State did not exist. This is a bug." ) ; else return this . states . get ( rule , index , ruleStart , ruleDot ) ; } public has ( rule , index , ruleStart , ruleDot ) { return this . states . has ( rule , index , ruleStart , ruleDot ) ; } }