File : store.ads


with Ada.Unchecked_Deallocation;
with Ints, Mods, Reps;
use Ints, Mods, Reps;

generic

  type Index is private;
  with function Empty return Index is <>;
  with function Hash(N: Index) return PMod is <>;

package Store is  -- storing volumes in forgetful hash table

  pragma Elaborate_Body;

  Filled: Int := 0;

  procedure Make_Empty_Table;
  procedure Free_Table;

  procedure FindVol(Key: in Index; I: out Int; V: out Rep; Found: out Boolean);
  procedure SaveVol(Key: in Index; I: in Int; V: in Rep);

private

  type Stored_Volume is
    record
      FaceId0: Index := Empty;   -- for zero volumes
      FaceId: Index := Empty;    -- for nonzero volumes
      VarsId: Int;
      Volume: Rep;
    end record;

  pragma Pack (Stored_Volume);   -- save space

  type Stored_Volumes is array(PMod range <>) of Stored_Volume;
  subtype SVPrim is Stored_Volumes(0 .. PMod(Prim-1));
  type SVPrimPtr is access all SVPrim;

  procedure Free is new Ada.Unchecked_Deallocation(SVPrim,SVPrimPtr);

  Table: SVPrimPtr;

end Store;