From fa1d949bf4bde18995750b2f85e3ac3ef0363f50 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Sat, 4 Jan 2025 05:08:03 +0000 Subject: [PATCH] checkpoint this mess --- developer/example/CountingNumber.java | 14 +-- developer/example/Example_CountingNumber.java | 4 +- developer/example/Example_SRMI_Array.java | 6 +- developer/example/Example_SRM_List.class | Bin 391 -> 2497 bytes developer/example/Example_SRM_List.java | 24 ++--- .../example/{ => hold}/Example_IndexTree_0 | 0 .../{ => hold}/Example_IndexTree_0.class | Bin .../{ => hold}/Example_IndexTree_0.java | 0 .../{ => hold}/Example_IndexTree_Diagonal_SRM | 0 .../Example_IndexTree_Diagonal_SRM.class | Bin .../Example_IndexTree_Diagonal_SRM.java | 0 .../{ => hold}/IndexTree_Diagonal_SRM.java | 0 .../javac\360\237\226\211/Ariadne_SRM.java" | 65 ++++++++---- .../javac\360\237\226\211/Ariadne_SRMI.java" | 30 +++--- .../Ariadne_SRMI_Array.java" | 74 ++++++++------ .../Ariadne_SRM_List.java" | 96 ++++++++---------- 16 files changed, 164 insertions(+), 149 deletions(-) rename developer/example/{ => hold}/Example_IndexTree_0 (100%) rename developer/example/{ => hold}/Example_IndexTree_0.class (100%) rename developer/example/{ => hold}/Example_IndexTree_0.java (100%) rename developer/example/{ => hold}/Example_IndexTree_Diagonal_SRM (100%) rename developer/example/{ => hold}/Example_IndexTree_Diagonal_SRM.class (100%) rename developer/example/{ => hold}/Example_IndexTree_Diagonal_SRM.java (100%) rename developer/example/{ => hold}/IndexTree_Diagonal_SRM.java (100%) diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java index c0f7871..0e000ec 100644 --- a/developer/example/CountingNumber.java +++ b/developer/example/CountingNumber.java @@ -15,12 +15,12 @@ public class CountingNumber extends Ariadne_SRM{ private BigInteger i; private BigInteger maximum; - Ariadne_SRM.Status status; + Ariadne_SRM.Location location; protected CountingNumber(BigInteger maximum){ i = BigInteger.ONE; this.maximum = maximum; - this.status = Status.LEFTMOST; + this.location = Location.LEFTMOST; test.print("CountingNumber read() value initialized to: " + i); } @@ -31,8 +31,8 @@ public class CountingNumber extends Ariadne_SRM{ } @Override - public Status status(){ - return status; + public Location location(){ + return location; } @Override @@ -47,9 +47,9 @@ public class CountingNumber extends Ariadne_SRM{ if(topology() == Topology.SEGMENT){ if(i.compareTo(maximum) == 0){ - status = Status.RIGHTMOST; - }else if(status() == Status.LEFTMOST){ - status = Status.INTERIM; + location = Location.RIGHTMOST; + }else if(location() == Location.LEFTMOST){ + location = Location.INTERIM; } } diff --git a/developer/example/Example_CountingNumber.java b/developer/example/Example_CountingNumber.java index a635ac0..3ff0f70 100644 --- a/developer/example/Example_CountingNumber.java +++ b/developer/example/Example_CountingNumber.java @@ -11,12 +11,12 @@ public class Example_CountingNumber{ protected static void print_ten(CountingNumber n){ System.out.println("Iterating through Counting Numbers:"); - if( !n.mounted() ) return; + if( !n.can_read() ) return; if(n.topology() == Ariadne_SRM.Topology.SEGMENT){ do{ System.out.println("Current Number: " + n.read()); - if( n.status() == Ariadne_SRM.Status.RIGHTMOST ) break; + if( n.location() == Ariadne_SRM.Location.RIGHTMOST ) break; n.step(); }while(true); diff --git a/developer/example/Example_SRMI_Array.java b/developer/example/Example_SRMI_Array.java index b3e9b99..9f1f6cf 100644 --- a/developer/example/Example_SRMI_Array.java +++ b/developer/example/Example_SRMI_Array.java @@ -16,17 +16,17 @@ public class Example_SRMI_Array { // Use the SRMI System.out.println( "Topology: " + srm.topology() ); - System.out.println( "Status: " + srm.status() ); + System.out.println( "Location: " + srm.location() ); // Traverse the list - while( srm.status() != Ariadne_SRM.Status.RIGHTMOST ) { + while( srm.location() != Ariadne_SRM.Location.RIGHTMOST ) { System.out.println( "Reading: " + srm.read() ); srm.step(); } // Final item System.out.println( "Reading: " + srm.read() ); - System.out.println( "Status: " + srm.status() ); + System.out.println( "Location: " + srm.location() ); */ } diff --git a/developer/example/Example_SRM_List.class b/developer/example/Example_SRM_List.class index acee04abde09f4a936352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3?dV`OeSAoo;^96RjHmqk%66o2`J70BpDf48Q6d%Cy=KP zq#1!UtJZb~#*JWUE+7e#29exAk_VyyNb>@DoD6&n{6G4T1mw diff --git a/developer/example/Example_SRM_List.java b/developer/example/Example_SRM_List.java index dd90028..486db68 100644 --- a/developer/example/Example_SRM_List.java +++ b/developer/example/Example_SRM_List.java @@ -4,32 +4,32 @@ import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; import java.util.LinkedList; public class Example_SRM_List { - public static void main(String[] args) { + public static void main(String[] args){ // Create a linked list - LinkedList labels = new LinkedList<>(); - labels.add("A"); - labels.add("B"); - labels.add("C"); + LinkedList label_list = new LinkedList<>(); + label_list.add("A"); + label_list.add("B"); + label_list.add("C"); // Attach SRM to the linked list - Ariadne_SRM_List srm = Ariadne_SRM_List.attach(labels); + Ariadne_SRM_List srm = Ariadne_SRM_List.make(label_list); // Use the SRM - System.out.println("Topology: " + srm.topology()); - System.out.println("Initial Status: " + srm.status()); + System.out.println( "Topology: " + srm.topology() ); + System.out.println( "Initial Location: " + srm.location() ); // Traverse the list - while (srm.status() != Ariadne_SRM.Status.RIGHTMOST) { + while( srm.location() != Ariadne_SRM.Location.RIGHTMOST ){ System.out.println("Reading: " + srm.read()); srm.step(); } // Final item - System.out.println("Reading: " + srm.read()); - System.out.println("Final Status: " + srm.status()); + System.out.println(" Reading: " + srm.read() ); + System.out.println(" Final Location: " + srm.location() ); // Reset the SRM and traverse again srm.reset(); - System.out.println("After reset: " + srm.read()); + System.out.println( "After reset: " + srm.read() ); } } diff --git a/developer/example/Example_IndexTree_0 b/developer/example/hold/Example_IndexTree_0 similarity index 100% rename from developer/example/Example_IndexTree_0 rename to developer/example/hold/Example_IndexTree_0 diff --git a/developer/example/Example_IndexTree_0.class b/developer/example/hold/Example_IndexTree_0.class similarity index 100% rename from developer/example/Example_IndexTree_0.class rename to developer/example/hold/Example_IndexTree_0.class diff --git a/developer/example/Example_IndexTree_0.java b/developer/example/hold/Example_IndexTree_0.java similarity index 100% rename from developer/example/Example_IndexTree_0.java rename to developer/example/hold/Example_IndexTree_0.java diff --git a/developer/example/Example_IndexTree_Diagonal_SRM b/developer/example/hold/Example_IndexTree_Diagonal_SRM similarity index 100% rename from developer/example/Example_IndexTree_Diagonal_SRM rename to developer/example/hold/Example_IndexTree_Diagonal_SRM diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.class b/developer/example/hold/Example_IndexTree_Diagonal_SRM.class similarity index 100% rename from developer/example/Example_IndexTree_Diagonal_SRM.class rename to developer/example/hold/Example_IndexTree_Diagonal_SRM.class diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.java b/developer/example/hold/Example_IndexTree_Diagonal_SRM.java similarity index 100% rename from developer/example/Example_IndexTree_Diagonal_SRM.java rename to developer/example/hold/Example_IndexTree_Diagonal_SRM.java diff --git a/developer/example/IndexTree_Diagonal_SRM.java b/developer/example/hold/IndexTree_Diagonal_SRM.java similarity index 100% rename from developer/example/IndexTree_Diagonal_SRM.java rename to developer/example/hold/IndexTree_Diagonal_SRM.java diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" index 2c34a8e..16fee89 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM.java" @@ -3,6 +3,9 @@ This is a mostly abstract base class. + This is for single threaded execution. The multiple thread model + uses `mount` and `dismount` to lock the resources being iterated on. + */ package com.ReasoningTechnology.Ariadne; @@ -16,45 +19,67 @@ public class Ariadne_SRM { } public enum Topology{ - NO_CELLS + UNDEFINED + ,NO_CELLS + ,SINGLETON ,SEGMENT + ,SEGMENT_OR_CIRCLE ,CIRCLE + ,CIRCLE_OR_INFINITE_RIGHT ,INFINITE_RIGHT - ,UNKNOWN - ,UNDEFINED ; } - public Topology topology(){ - return Topology.UNDEFINED; - } - - // categorizes the head location - public enum Status{ - TAPE_NOT_MOUNTED + public enum Location{ + OTHER ,LEFTMOST ,INTERIM ,RIGHTMOST ; } - public Status status(){ - throw new UnsupportedOperationException("Ariadne_SRM::status not implemented."); + + public Topology topology(){ + return Topology.UNDEFINED; + } + public Location location(){ + throw new UnsupportedOperationException("Ariadne_SRM::location not implemented."); } - public boolean can_step(){ - return - status() == Status.LEFTMOST - || status() == Status.INTERIM; + public boolean can_step() { + return topology().ordinal() >= Topology.SEGMENT.ordinal() + && location().ordinal() <= Location.INTERIM.ordinal(); } - public boolean mounted(){ - return status() != Status.TAPE_NOT_MOUNTED; + + public boolean can_read() { + return topology().ordinal() >= Topology.SINGLETON.ordinal(); + } + + // returns a reference, cell can then be read or written + public TElement access(){ + throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); } public TElement read(){ + TElement accessed_cell = access(); + return deep_copy( accessed_cell ); + } + private TElement deep_copy( TElement original ){ + throw new UnsupportedOperationException("Ariadne_SRM::deep_copy not implemented."); + } + + // writes value + public void write(TElement e){ throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); } public void step(){ - if( !can_step() ) - throw new UnsupportedOperationException("Ariadne_SRM::step can not step."); + throw new UnsupportedOperationException("Ariadne_SRM::step not implemented."); + } + + public void rewind(){ + throw new UnsupportedOperationException("Ariadne_SRM::rewind not implemented."); + } + + public void fast_forward(){ + throw new UnsupportedOperationException("Ariadne_SRM::fast_forward not implemented."); } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" index cdb49a1..c4b3dfe 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" @@ -4,32 +4,28 @@ Ariadne_SRM with index */ package com.ReasoningTechnology.Ariadne; -import java.math.BigInteger; -public class Ariadne_SRMI extends Ariadne_SRM{ +public class Ariadne_SRMI extends Ariadne_SRM{ - protected BigInteger index; - - public static Ariadne_SRMI make(){ - return new Ariadne_SRMI(); + public static Ariadne_SRMI make(){ + return new Ariadne_SRMI(); } protected Ariadne_SRMI(){ - super(); - index = BigInteger.ZERO;; } - @Override - public void step(){ - throw new UnsupportedOperationException("Ariadne_SRMI::can't step unmounted tape."); -// index.add(BigInteger.ONE); + public int index(){ + throw new UnsupportedOperationException("Ariadne_SRMI::index not implemented."); } - BigInteger index(){return index;} - BigInteger leftmost_index(){ - return BigInteger.ZERO; + public int leftmost_index(){ + throw new UnsupportedOperationException("Ariadne_SRMI::leftmost_index not implemented."); + } + public int rightmost_index(){ + throw new UnsupportedOperationException("Ariadne_SRMI::rightmost_index not implemented."); } - BigInteger rightmost_index(){ - throw new UnsupportedOperationException("Ariadne_SRMI:: rightmost_index() of undefined."); + + void seek(int i){ + throw new UnsupportedOperationException("Ariadne_SRMI::seek not implemented."); } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" index 94fcbb7..5e95b45 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" @@ -1,62 +1,70 @@ package com.ReasoningTechnology.Ariadne; - -import java.math.BigInteger; import java.util.List; -import java.util.concurrent.Semaphore; public class Ariadne_SRMI_Array extends Ariadne_SRMI{ - private List list; - private Semaphore lock; - - public static Ariadne_SRMI_Array make(){ - return new Ariadne_SRMI_Array<>(); + public static Ariadne_SRMI_Array make(List array){ + return new Ariadne_SRMI_Array<>(array); } + private List _array; + private int _index; + private Topology _topology; + private Location _location; + protected Ariadne_SRMI_Array(){ - super(); + _array = array; + + if( _array == null || _array.isEmpty() ) + _topology = Topology.NO_CELLS; + else if( _array.size() == 1 ) + _topology = Topology.SINGLETON; + else + _topology = Topology.SEGMENT; + + if(_topology == Topology.SEGMENT) + _location = Location.LEFTMOST; + else + _location = Location.OTHER; + + _index = 0; } @Override public Topology topology(){ - if(list == null || list.isEmpty()){ - return Topology.NO_CELLS; - } - return Topology.SEGMENT; + return _topology; } @Override - public Status status(){ - return super.status(); + public Location location(){ + return _location; } @Override - public T read(){ - if(!mounted()){ - throw new UnsupportedOperationException("Ariadne_SRMI_Array::read tape not mounted or out of bounds."); - } - return list.get(index().intValue()); + public T access(){ + if( can_read() ) return _array.get( _index() ); + throw new UnsupportedOperationException("Ariadne_SRMI_Array::read can not read tape."); } @Override public void step(){ - if(!can_step()){ - throw new UnsupportedOperationException("Ariadne_SRMI_Array::step, cannot step further."); - } - if(index().compareTo(rightmost_index()) < 0){ - index = index.add(BigInteger.ONE); -// set_status(index().equals(rightmost_index()) ? Status.RIGHTMOST : Status.INTERIM); - } else{ - throw new UnsupportedOperationException("Ariadne_SRMI_Array::step, no more cells."); + if( can_step() ){ + _index++; + if( _index == _array.size() - 1 ) _location = Location.RIGHTMOST; + return; } + throw new UnsupportedOperationException("Ariadne_SRMI_Array::step can not step."); } @Override - public BigInteger rightmost_index(){ - if(list == null){ - throw new UnsupportedOperationException("Ariadne_SRMI_Array::rightmost_index no tape mounted."); - } - return BigInteger.valueOf(list.size() - 1); + public int leftmost_index(){ + return 0; + } + + @Override + public int rightmost_index(){ + if( can_read() ) return _array.size() - 1; + throw new UnsupportedOperationException("Ariadne_SRMI_Array::rightmost_index can not read array."); } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" index db8fd48..49c20bb 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" @@ -1,14 +1,8 @@ /* The Ariadne_SRM_List class provides a Step Right Machine (SRM) for linked lists. - This implementation relies on Java's ListIterator, which lacks a direct method - to read the current element without advancing the iterator. + This implementation uses Java's ListIterator, which lacks a direct method + to read the current element without advancing the iterator. - To address this, the `read` method temporarily moves the iterator back to access - the current element, then restores its position. This approach, referred to as the - "wiggle" method, is safe under the assumption of single-threaded execution. - - In multi-threaded environments, external synchronization would be required to - ensure the list remains consistent during the wiggle operation. */ package com.ReasoningTechnology.Ariadne; @@ -16,74 +10,66 @@ package com.ReasoningTechnology.Ariadne; import java.util.List; import java.util.ListIterator; -public class Ariadne_SRM_List extends Ariadne_SRM { - - private final List list; // The attached linked list - private ListIterator iterator; // Iterator for traversal +public class Ariadne_SRM_List extends Ariadne_SRM { - public static Ariadne_SRM_List mount(List list){ + public static Ariadne_SRM_List make(List list){ return new Ariadne_SRM_List<>(list); } - protected Ariadne_SRM_List(List list){ - if (list == null){ - throw new IllegalArgumentException("Ariadne_SRM_List::list cannot be null"); + private final List _list; // The attached linked list + private ListIterator iterator; // Iterator for traversal + private TElement read_value; // Stores the current cell value + + private Topology _topology; + private Location _location; + + // Protected constructor for controlled instantiation + protected Ariadne_SRM_List(List list){ + _list = list; + + if( _list == null || _list.isEmpty() ) + _topology = Topology.NO_CELLS; + else if( _list.size() == 1 ) + _topology = Topology.SINGLETON; + else + _topology = Topology.SEGMENT; + + if(_topology == Topology.SEGMENT) + _location = Location.LEFTMOST; + else + _location = Location.OTHER; + + if(_topology >= SINGLETON){ + iterator = _list.listIterator(); + read_value = iterator.next(); } - this.list = list; - this.iterator = list.listIterator(); } @Override public Topology topology(){ - return list.isEmpty() ? Topology.NO_CELLS : Topology.SEGMENT; + return _topology; } @Override - public Status status(){ - if (list.isEmpty()){ - return Status.TAPE_NOT_MOUNTED; - } - if (!iterator.hasPrevious() && iterator.hasNext()){ - return Status.LEFTMOST; - } - if (!iterator.hasNext() && iterator.hasPrevious()){ - return Status.RIGHTMOST; - } - if (iterator.hasNext() && iterator.hasPrevious()){ - return Status.INTERIM; - } - return Status.TAPE_NOT_MOUNTED; // Fallback, should not occur + public Location location(){ + return _location; } @Override - public T read(){ - if (status() == Status.TAPE_NOT_MOUNTED){ - throw new UnsupportedOperationException("Ariadne_SRM_List::read, tape not mounted."); - } - if (!iterator.hasPrevious()){ - throw new UnsupportedOperationException("Ariadne_SRM_List::read, no cell to read at the leftmost position."); - } - // Wiggle: Move back to read the current element, then restore position - T previous = iterator.previous(); - iterator.next(); // Restore iterator to the current position - return previous; + public TElement access(){ + if( can_read() ) return read_value; + throw new UnsupportedOperationException("Ariadne_SRM_List::access can not read tape."); } @Override public void step(){ - if (!iterator.hasNext()){ - throw new UnsupportedOperationException("Ariadne_SRM_List::step, no next cell."); + if( can_step() ){ + read_value = iterator.next(); // Move to the next cell and update current value + if( !iterator.has_next() ) _location = Location.RIGHTMOST; + return; } - iterator.next(); + throw new UnsupportedOperationException("Ariadne_SRM_List::step can not step."); } - // Optional: Reset to the beginning of the list - public void reset(){ - this.iterator = list.listIterator(); - } - // Optional: Get the underlying linked list - public List getList(){ - return list; - } } -- 2.20.1