aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2026-01-19 15:21:43 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2026-01-19 15:21:43 +1300
commitf6cc00c7e53ea5bc6fa19177bdb98ddcf25440d0 (patch)
tree6b0c302bc48801e983bca6066e1915611ca4673a /src
parent0c3e440a6eaf45e83654e9d8f5471e88a2eacf77 (diff)
State now uses a Vector instead of a Map
Diffstat (limited to 'src')
-rw-r--r--src/kompsos-collector.adb12
-rw-r--r--src/kompsos-pretty_print.adb6
-rw-r--r--src/kompsos.adb35
-rw-r--r--src/kompsos.ads21
4 files changed, 55 insertions, 19 deletions
diff --git a/src/kompsos-collector.adb b/src/kompsos-collector.adb
index 7d48196..e3c760e 100644
--- a/src/kompsos-collector.adb
+++ b/src/kompsos-collector.adb
@@ -65,10 +65,12 @@ package body Kompsos.Collector is
procedure Walk
(This : in State;
- Item : in out Term) is
+ Item : in out Term)
+ is
+ Bound_Term : Term;
begin
- while Item.Kind = Var_Term and then This.Actual.Contains (Item.Var) loop
- Item := This.Actual.Element (Item.Var);
+ while Item.Kind = Var_Term and then Lookup (This, Item.Var, Bound_Term) loop
+ Item := Bound_Term;
end loop;
end Walk;
@@ -102,12 +104,12 @@ package body Kompsos.Collector is
-- Unify Variable and other Terms by introducing a new substitution
if Real_Left.Kind = Var_Term then
Extended := Potential;
- Extended.Actual.Insert (Real_Left.Var, Real_Right);
+ Extended.Actual.Append ((Real_Left.Var, Real_Right));
return True;
end if;
if Real_Right.Kind = Var_Term then
Extended := Potential;
- Extended.Actual.Insert (Real_Right.Var, Real_Left);
+ Extended.Actual.Append ((Real_Right.Var, Real_Left));
return True;
end if;
diff --git a/src/kompsos-pretty_print.adb b/src/kompsos-pretty_print.adb
index 3a65fb9..a9ba9e2 100644
--- a/src/kompsos-pretty_print.adb
+++ b/src/kompsos-pretty_print.adb
@@ -97,10 +97,10 @@ package body Kompsos.Pretty_Print is
if Item.Actual.Is_Empty then
SU.Append (Result, Latin.HT & "N/A" & Latin.LF);
else
- for Iter in Item.Actual.Iterate loop
+ for Bind of Item.Actual loop
SU.Append (Result, Latin.HT &
- Image (Binding_Maps.Key (Iter)) & " => " &
- Image (Binding_Maps.Element (Iter)) & Latin.LF);
+ Image (Bind.Key) & " => " &
+ Image (Bind.Elem) & Latin.LF);
end loop;
end if;
return SU.To_String (Result);
diff --git a/src/kompsos.adb b/src/kompsos.adb
index 4a34b1b..ae7848d 100644
--- a/src/kompsos.adb
+++ b/src/kompsos.adb
@@ -209,6 +209,25 @@ package body Kompsos is
+ -- States --
+
+ function Lookup
+ (This : in State;
+ Key : in Variable;
+ Value : out Term'Class)
+ return Boolean is
+ begin
+ for Bind of This.Actual loop
+ if Bind.Key = Key then
+ Value := Term'Class (Bind.Elem);
+ return True;
+ end if;
+ end loop;
+ return False;
+ end Lookup;
+
+
+
-- Goal Graphs --
package Graph_Convert is new System.Address_To_Access_Conversions (Graph_Component);
@@ -550,11 +569,15 @@ package body Kompsos is
when Null_Term | Atom_Term =>
return This;
when Var_Term =>
- if Subst.Actual.Contains (This.Var) then
- return Subst.Actual.Element (This.Var).Resolve (Subst);
- else
- return This;
- end if;
+ declare
+ Bound_Term : Term;
+ begin
+ if Lookup (Subst, This.Var, Bound_Term) then
+ return Bound_Term.Resolve (Subst);
+ else
+ return This;
+ end if;
+ end;
when Pair_Term =>
return T (This.Left.Resolve (Subst), This.Right.Resolve (Subst));
end case;
@@ -568,7 +591,7 @@ package body Kompsos is
if Subst.Actual.Is_Empty then
return Empty_Term;
else
- return Subst.Actual.First_Element.Resolve (Subst);
+ return Subst.Actual.First_Element.Elem.Resolve (Subst);
end if;
end Resolve_First;
diff --git a/src/kompsos.ads b/src/kompsos.ads
index 9ab7994..9a00251 100644
--- a/src/kompsos.ads
+++ b/src/kompsos.ads
@@ -463,15 +463,26 @@ private
- package Binding_Maps is new Ada.Containers.Ordered_Maps
- (Key_Type => Variable,
- Element_Type => Term);
+ type Binding is record
+ Key : Variable;
+ Elem : Term;
+ end record;
+
+ package Binding_Vectors is new Ada.Containers.Vectors
+ (Index_Type => Long_Positive,
+ Element_Type => Binding);
type State is record
- Actual : Binding_Maps.Map;
+ Actual : Binding_Vectors.Vector;
end record;
- Empty_State : constant State := (Actual => Binding_Maps.Empty_Map);
+ function Lookup
+ (This : in State;
+ Key : in Variable;
+ Value : out Term'Class)
+ return Boolean;
+
+ Empty_State : constant State := (Actual => Binding_Vectors.Empty_Vector);