import { Dict , keys } from './util' ; import { Property , toKey } from './property' ; export interface PropIndexReader < T > { has ( p ) : boolean ; get ( p ) : T ; } /**
 * Dictionary that takes property as a key.
 */ export class PropIndex < T > implements PropIndexReader < T > { private index : Dict < T > ; constructor ( i = null ) { this . index = i ? { ... i } : { } ; } public has ( p ) { return toKey ( p ) in this . index ; } public get ( p ) { return this . index [ toKey ( p ) ] ; } public set ( p , value ) { this . index [ toKey ( p ) ] = value ; return this ; } public setByKey ( key , value ) { this . index [ key ] = value ; } public map < U > ( f ) { const i = new PropIndex < U > ( ) ; for ( const k in this . index ) { i . index [ k ] = f ( this . index [ k ] ) ; } return i ; } public size ( ) { return keys ( this . index ) . length ; } public duplicate ( ) { return new PropIndex < T > ( this . index ) ; } }