UNPKG

acsets

Version:

An implementation of acsets in typescript, compatible with ACSets.jl and pyacsets

121 lines (99 loc) 3.63 kB
import { Schema, Ob, Property } from './schema'; export interface ExportedPart { _id: number; [prop: string]: any; } export interface ExportedACSet { [ob: string]: ExportedPart[]; } /** An acset consists of a collection of tables, one for every object in the schema. The rows of the tables are called "parts", and the cells of the rows are called "subparts". One can get all of the parts corresponding to an object, add parts, get the subparts, and set the subparts. Removing parts is currently unsupported. */ export declare class ACSet { name: string; schema: Schema; private _parts; private _subparts; /** Initialize a new ACSet. @param name - The name of the ACSset. @param schema - The schema of the ACSet. */ constructor(name: string, schema: Schema); /** Add `n` parts to an object in the ACset. @param ob - The object in the ACSet to add parts to. @param n - The number of parts to be added. @returns A range of the indexes of the new parts added to the object. */ addParts(ob: Ob, n: number): [number, number]; /** Add a single part to an object in the ACSet @param ob - The object in the ACSet to add a part to. @returns The index of the new part added to the object. */ addPart(ob: Ob): number; /** Checks whether a certain part exists in the ACSet */ hasPart(ob: Ob, i: number): boolean; /** Check if a property exists for a given row in a table of the ACSset. @param i - The row index for the property mapping to be added to. @param f - The `Hom` or `Attr` to check for. @param `True` if the property `f` exists on row `i` or `False` if it doesn't. */ hasSubpart(i: number, f: Property): boolean; /** Modify a morphism or attribute for a row in a table of the ACSet. @param i - The row index for the property mapping to be added to. @param f - The `Hom` or `Attr` to modify. @param x - A valid type for the given `Hom` or `Attr` to set the value or `None` to delete the property. */ setSubpart(i: number, f: Property, x: any): void; /** Get the subpart of a part in an ACSet @param i - The part that you are indexing. @param f - The `Hom` or `Attr` to retrieve. @returns The subpart of the ACset. */ subpart(i: number, f: Property): any; /** Get the number of rows in a given table of the ACSet. @param ob - The object in the ACSet. @returns The number of rows in `ob`. */ nparts(ob: Ob): number; /** Get all of the row indexes in a given table of the ACSet. @param ob - The object in the ACSet. @returns The range of all of the rows in `ob`. */ parts(ob: Ob): [number, number]; partArray(ob: Ob): number[]; /** Get all of the subparts incident to a part in the ACset. @param x - The subpart to look for. @param f - The `Hom` or `Attr` mapping to search. @returns A list indexes. */ incident(x: any, f: Property): number[]; private exportPart; private importPart; /** Serialize the ACSet to a JSON object. @returns The JSON object of the serialized ACSet. */ export(): ExportedACSet; /** Deserialize a JSON object to an ACSet with a given `Schema`. @param name - The name of the ACSset. @param schema - The `Schema` of the ACSet that is defined in the given JSON. @param s - The JSON object @returns The deserialized ACSet object. */ static import(name: string, schema: Schema, exported: ExportedACSet): ACSet; }