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);
}
}
@Override
- public Status status(){
- return status;
+ public Location location(){
+ return location;
}
@Override
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;
}
}
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);
+++ /dev/null
-#!/bin/bash
-java Example_IndexTree_0
+++ /dev/null
-import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Child_SRM;
-import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
-import java.math.BigInteger;
-
-public class Example_IndexTree_0{
-
- public static void traverse_index_tree(){
- System.out.println("Starting Index Tree Traversal:");
-
- Ariadne_IndexTree_Node root_node = Ariadne_IndexTree_Node.make(new BigInteger[0]);
- System.out.println("Root Node: " + format_label(root_node.label()));
-
- Ariadne_IndexTree_Node current_node = root_node;
- int depth_count = 0;
- do{
- Ariadne_IndexTree_Child_SRM depth_srm = current_node.neighbor();
- BigInteger[] depth_label = depth_srm.read();
- System.out.println("Step " + (depth_count + 1) + " Down: " + format_label(depth_label));
- current_node = Ariadne_IndexTree_Node.make(depth_label);
-
- // precise loop termination
- if(depth_count == 3) break;
- depth_count++;
- }while(true);
-
- Ariadne_IndexTree_Child_SRM child_srm = current_node.neighbor();
- int child_count = 0;
- do{
- BigInteger[] child_label = child_srm.read();
- System.out.println("Step " + (child_count + 1) + " Across: " + format_label(child_label));
-
- // precise loop termination
- if(child_count == 3) break; // Mid-loop test for inclusive bound
- child_count++;
- child_srm.step();
- }while(true);
- }
-
- private static String format_label(BigInteger[] label){
- if(label.length == 0) return "[]";
- StringBuilder formatted = new StringBuilder("[");
- for(int i = 0 ;i < label.length ;i++){
- formatted.append(label[i].toString());
- if(i < label.length - 1) formatted.append(" ,");
- }
- formatted.append("]");
- return formatted.toString();
- }
-
- public static void main(String[] args){
- traverse_index_tree();
- }
-}
+++ /dev/null
-#!/bin/bash
-java Example_IndexTree_Diagonal_SRM
+++ /dev/null
-import java.math.BigInteger;
-import java.util.Queue;
-
-public class Example_IndexTree_Diagonal_SRM {
-
- public static void main(String[] args){
- System.out.println("Starting IndexTree SRM Example");
-
- // Instantiate the IndexTree Diagonal SRM
- IndexTree_Diagonal_SRM srm = IndexTree_Diagonal_SRM.make();
-
- int step_count = 0;
- do{
- System.out.println("Step " + (step_count + 1) + ":");
- /*
- Queue<BigInteger[]> read_list = srm.read();
- if(!read_list.isEmpty()){
- for(BigInteger[] label : read_list){
- System.out.println(" Node Label: " + format_label(label));
- }
- }
- */
- if(step_count == 3) break; // Mid-loop test for inclusive bounds
- step_count++;
- srm.step();
- }while(true);
- }
-
- private static String format_label(BigInteger[] label){
- if(label.length == 0) return "[]";
- StringBuilder formatted = new StringBuilder("[");
- for(int i = 0; i < label.length; i++){
- formatted.append(label[i].toString());
- if(i < label.length - 1) formatted.append(" ,");
- }
- formatted.append("]");
- return formatted.toString();
- }
-}
// 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() );
*/
}
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<String> labels = new LinkedList<>();
- labels.add("A");
- labels.add("B");
- labels.add("C");
+ LinkedList<String> 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<String> srm = Ariadne_SRM_List.attach(labels);
+ Ariadne_SRM_List<String> 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() );
}
}
+++ /dev/null
-import java.math.BigInteger;
-import com.ReasoningTechnology.Ariadne.Ariadne_Test;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
-import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
-
-public class IndexTree_Diagonal_SRM extends Ariadne_SRM<BigInteger[]> {
-
- private final Ariadne_SRM_List<Ariadne_IndexTree_Node> list_of__unopened_node;
- private final Ariadne_SRM_List<Ariadne_SRM_List<Ariadne_IndexTree_Node>> list_of__opened_incomplete_child_list;
- private final Ariadne_SRM_List<BigInteger[]> read_list;
- private final Ariadne_Test tester;
-
- public static IndexTree_Diagonal_SRM make(){
- return new IndexTree_Diagonal_SRM();
- }
-
- protected IndexTree_Diagonal_SRM(){
- this.list_of__unopened_node = new Ariadne_SRM_List<>();
- this.list_of__opened_incomplete_child_list = new Ariadne_SRM_List<>();
- this.read_list = new Ariadne_SRM_List<>();
- this.tester = Ariadne_Test.make("IndexTree_Diagonal_SRM: ");
- enqueue_root();
- }
-
- @Override
- public void step(){
- super.step();
-
- read_list.clear(); // Clear the current read list for the new diagonal
-
- // Process unopened nodes
- while(!list_of__unopened_node.is_empty()){
- Ariadne_IndexTree_Node node = list_of__unopened_node.read();
- list_of__unopened_node.step(); // Remove node from unopened list
- Ariadne_SRM_List<Ariadne_IndexTree_Node> child_list = node.open();
- if(child_list != null){
- list_of__opened_incomplete_child_list.add(child_list);
- }
- }
-
- // Process incomplete child lists
- while(!list_of__opened_incomplete_child_list.is_empty()){
- Ariadne_SRM_List<Ariadne_IndexTree_Node> child_list = list_of__opened_incomplete_child_list.read();
- if(!child_list.is_empty()){
- Ariadne_IndexTree_Node node = child_list.read();
- child_list.step(); // Step to the next node in the child list
- BigInteger[] label = node.label();
- read_list.add(label); // Queue the label on the read list
- tester.print("Queued label: " + format_label(label));
- if(node.has_children()){
- list_of__unopened_node.add(node); // Add node to unopened list if it has children
- }
- if(child_list.is_empty()){
- list_of__opened_incomplete_child_list.step(); // Remove empty child lists
- }
- }
- }
- }
-
- private void enqueue_root(){
- Ariadne_IndexTree_Node root = Ariadne_IndexTree_Node.make(new BigInteger[0]);
- read_list.add(root.label());
- tester.print("Queued root label: " + format_label(root.label()));
- if(root.has_children()){
- list_of__unopened_node.add(root);
- }
- }
-
- private String format_label(BigInteger[] label){
- if(label.length == 0) return "[]";
- StringBuilder formatted = new StringBuilder("[");
- for(int i = 0; i < label.length; i++){
- formatted.append(label[i].toString());
- if(i < label.length - 1) formatted.append(" ,");
- }
- formatted.append("]");
- return formatted.toString();
- }
-}
--- /dev/null
+#!/bin/bash
+java Example_IndexTree_0
--- /dev/null
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Child_SRM;
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
+import java.math.BigInteger;
+
+public class Example_IndexTree_0{
+
+ public static void traverse_index_tree(){
+ System.out.println("Starting Index Tree Traversal:");
+
+ Ariadne_IndexTree_Node root_node = Ariadne_IndexTree_Node.make(new BigInteger[0]);
+ System.out.println("Root Node: " + format_label(root_node.label()));
+
+ Ariadne_IndexTree_Node current_node = root_node;
+ int depth_count = 0;
+ do{
+ Ariadne_IndexTree_Child_SRM depth_srm = current_node.neighbor();
+ BigInteger[] depth_label = depth_srm.read();
+ System.out.println("Step " + (depth_count + 1) + " Down: " + format_label(depth_label));
+ current_node = Ariadne_IndexTree_Node.make(depth_label);
+
+ // precise loop termination
+ if(depth_count == 3) break;
+ depth_count++;
+ }while(true);
+
+ Ariadne_IndexTree_Child_SRM child_srm = current_node.neighbor();
+ int child_count = 0;
+ do{
+ BigInteger[] child_label = child_srm.read();
+ System.out.println("Step " + (child_count + 1) + " Across: " + format_label(child_label));
+
+ // precise loop termination
+ if(child_count == 3) break; // Mid-loop test for inclusive bound
+ child_count++;
+ child_srm.step();
+ }while(true);
+ }
+
+ private static String format_label(BigInteger[] label){
+ if(label.length == 0) return "[]";
+ StringBuilder formatted = new StringBuilder("[");
+ for(int i = 0 ;i < label.length ;i++){
+ formatted.append(label[i].toString());
+ if(i < label.length - 1) formatted.append(" ,");
+ }
+ formatted.append("]");
+ return formatted.toString();
+ }
+
+ public static void main(String[] args){
+ traverse_index_tree();
+ }
+}
--- /dev/null
+#!/bin/bash
+java Example_IndexTree_Diagonal_SRM
--- /dev/null
+import java.math.BigInteger;
+import java.util.Queue;
+
+public class Example_IndexTree_Diagonal_SRM {
+
+ public static void main(String[] args){
+ System.out.println("Starting IndexTree SRM Example");
+
+ // Instantiate the IndexTree Diagonal SRM
+ IndexTree_Diagonal_SRM srm = IndexTree_Diagonal_SRM.make();
+
+ int step_count = 0;
+ do{
+ System.out.println("Step " + (step_count + 1) + ":");
+ /*
+ Queue<BigInteger[]> read_list = srm.read();
+ if(!read_list.isEmpty()){
+ for(BigInteger[] label : read_list){
+ System.out.println(" Node Label: " + format_label(label));
+ }
+ }
+ */
+ if(step_count == 3) break; // Mid-loop test for inclusive bounds
+ step_count++;
+ srm.step();
+ }while(true);
+ }
+
+ private static String format_label(BigInteger[] label){
+ if(label.length == 0) return "[]";
+ StringBuilder formatted = new StringBuilder("[");
+ for(int i = 0; i < label.length; i++){
+ formatted.append(label[i].toString());
+ if(i < label.length - 1) formatted.append(" ,");
+ }
+ formatted.append("]");
+ return formatted.toString();
+ }
+}
--- /dev/null
+import java.math.BigInteger;
+import com.ReasoningTechnology.Ariadne.Ariadne_Test;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM;
+import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List;
+import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node;
+
+public class IndexTree_Diagonal_SRM extends Ariadne_SRM<BigInteger[]> {
+
+ private final Ariadne_SRM_List<Ariadne_IndexTree_Node> list_of__unopened_node;
+ private final Ariadne_SRM_List<Ariadne_SRM_List<Ariadne_IndexTree_Node>> list_of__opened_incomplete_child_list;
+ private final Ariadne_SRM_List<BigInteger[]> read_list;
+ private final Ariadne_Test tester;
+
+ public static IndexTree_Diagonal_SRM make(){
+ return new IndexTree_Diagonal_SRM();
+ }
+
+ protected IndexTree_Diagonal_SRM(){
+ this.list_of__unopened_node = new Ariadne_SRM_List<>();
+ this.list_of__opened_incomplete_child_list = new Ariadne_SRM_List<>();
+ this.read_list = new Ariadne_SRM_List<>();
+ this.tester = Ariadne_Test.make("IndexTree_Diagonal_SRM: ");
+ enqueue_root();
+ }
+
+ @Override
+ public void step(){
+ super.step();
+
+ read_list.clear(); // Clear the current read list for the new diagonal
+
+ // Process unopened nodes
+ while(!list_of__unopened_node.is_empty()){
+ Ariadne_IndexTree_Node node = list_of__unopened_node.read();
+ list_of__unopened_node.step(); // Remove node from unopened list
+ Ariadne_SRM_List<Ariadne_IndexTree_Node> child_list = node.open();
+ if(child_list != null){
+ list_of__opened_incomplete_child_list.add(child_list);
+ }
+ }
+
+ // Process incomplete child lists
+ while(!list_of__opened_incomplete_child_list.is_empty()){
+ Ariadne_SRM_List<Ariadne_IndexTree_Node> child_list = list_of__opened_incomplete_child_list.read();
+ if(!child_list.is_empty()){
+ Ariadne_IndexTree_Node node = child_list.read();
+ child_list.step(); // Step to the next node in the child list
+ BigInteger[] label = node.label();
+ read_list.add(label); // Queue the label on the read list
+ tester.print("Queued label: " + format_label(label));
+ if(node.has_children()){
+ list_of__unopened_node.add(node); // Add node to unopened list if it has children
+ }
+ if(child_list.is_empty()){
+ list_of__opened_incomplete_child_list.step(); // Remove empty child lists
+ }
+ }
+ }
+ }
+
+ private void enqueue_root(){
+ Ariadne_IndexTree_Node root = Ariadne_IndexTree_Node.make(new BigInteger[0]);
+ read_list.add(root.label());
+ tester.print("Queued root label: " + format_label(root.label()));
+ if(root.has_children()){
+ list_of__unopened_node.add(root);
+ }
+ }
+
+ private String format_label(BigInteger[] label){
+ if(label.length == 0) return "[]";
+ StringBuilder formatted = new StringBuilder("[");
+ for(int i = 0; i < label.length; i++){
+ formatted.append(label[i].toString());
+ if(i < label.length - 1) formatted.append(" ,");
+ }
+ formatted.append("]");
+ return formatted.toString();
+ }
+}
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;
}
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.");
}
}
*/
package com.ReasoningTechnology.Ariadne;
-import java.math.BigInteger;
-public class Ariadne_SRMI<T> extends Ariadne_SRM<T>{
+public class Ariadne_SRMI<TElement> extends Ariadne_SRM<TElement>{
- protected BigInteger index;
-
- public static <T> Ariadne_SRMI<T> make(){
- return new Ariadne_SRMI<T>();
+ public static <TElement> Ariadne_SRMI<TElement> make(){
+ return new Ariadne_SRMI<TElement>();
}
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.");
}
}
package com.ReasoningTechnology.Ariadne;
-
-import java.math.BigInteger;
import java.util.List;
-import java.util.concurrent.Semaphore;
public class Ariadne_SRMI_Array<T> extends Ariadne_SRMI<T>{
- private List<T> list;
- private Semaphore lock;
-
- public static <T> Ariadne_SRMI_Array<T> make(){
- return new Ariadne_SRMI_Array<>();
+ public static <T> Ariadne_SRMI_Array<T> make(List<T> array){
+ return new Ariadne_SRMI_Array<>(array);
}
+ private List<T> _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.");
}
}
/*
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;
import java.util.List;
import java.util.ListIterator;
-public class Ariadne_SRM_List<T> extends Ariadne_SRM<T> {
-
- private final List<T> list; // The attached linked list
- private ListIterator<T> iterator; // Iterator for traversal
+public class Ariadne_SRM_List<TElement> extends Ariadne_SRM<TElement> {
- public static <T> Ariadne_SRM_List<T> mount(List<T> list){
+ public static <TElement> Ariadne_SRM_List<TElement> make(List<TElement> list){
return new Ariadne_SRM_List<>(list);
}
- protected Ariadne_SRM_List(List<T> list){
- if (list == null){
- throw new IllegalArgumentException("Ariadne_SRM_List::list cannot be null");
+ private final List<TElement> _list; // The attached linked list
+ private ListIterator<TElement> 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<TElement> 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<T> getList(){
- return list;
- }
}