From 2ccdc79d782ad1cd8bf76faf50e083d6edb5ecf8 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Thu, 9 Mar 2023 10:14:29 -0800 Subject: [PATCH 1/6] Added my name to Queue --- src/edu/greenriver/sdev333/Queue.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/edu/greenriver/sdev333/Queue.java b/src/edu/greenriver/sdev333/Queue.java index 638d71c..9d08216 100644 --- a/src/edu/greenriver/sdev333/Queue.java +++ b/src/edu/greenriver/sdev333/Queue.java @@ -3,6 +3,7 @@ import java.util.Iterator; /** + * Kevin Stone * FIFO queue, page 151 of the red book */ public class Queue implements Iterable { From efc647f74b29d41a82c2f5facc499a5374e90982 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Thu, 9 Mar 2023 10:34:20 -0800 Subject: [PATCH 2/6] Completed difference method in BSTSet --- src/edu/greenriver/sdev333/BSTSet.java | 125 +++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/edu/greenriver/sdev333/BSTSet.java diff --git a/src/edu/greenriver/sdev333/BSTSet.java b/src/edu/greenriver/sdev333/BSTSet.java new file mode 100644 index 0000000..9404b00 --- /dev/null +++ b/src/edu/greenriver/sdev333/BSTSet.java @@ -0,0 +1,125 @@ +package edu.greenriver.sdev333; + +import java.util.Iterator; + +public class BSTSet> implements MathSet { + + private class Node { + private KeyType key; + private Node left; + private Node right; + private int N; + + public Node(KeyType key, int N) { + this.key = key; + this.N = N; + } + } + + // field + private Node root; + + /** + * Puts the specified key into the set. + * + * @param key key to be added into the set + */ + @Override + public void add(KeyType key) { + + } + + /** + * Is the key in the set? + * + * @param key key to check + * @return true if key is in the set, false otherwise + */ + @Override + public boolean contains(KeyType key) { + return false; + } + + /** + * Is the set empty? + * + * @return true if the set is empty, false otherwise + */ + @Override + public boolean isEmpty() { + return false; + } + + /** + * Number of keys in the set + * + * @return number of keys in the set. + */ + @Override + public int size() { + return 0; + } + + /** + * Determine the union of this set with another specified set. + * Returns A union B, where A is this set, B is other set. + * A union B = {key | A.contains(key) OR B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to union + * @return the union of this set with other + */ + @Override + public MathSet union(MathSet other) { + return null; + } + + /** + * Determine the intersection of this set with another specified set. + * Returns A intersect B, where A is this set, B is other set. + * A intersect B = {key | A.contains(key) AND B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to intersect + * @return the intersection of this set with other + */ + @Override + public MathSet intersection(MathSet other) { + return null; + } + + /** + * Determine the difference of this set with another specified set. + * Returns A difference B, where A is this set, B is other set. + * A difference B = {key | A.contains(key) AND !B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to difference + * @return the difference of this set with other + */ + @Override + public MathSet difference(MathSet other) { + // create an empty set that will hold the result + MathSet result = new BSTSet(); + + // iterate through all of the items in this + Iterator itr = (Iterator) this.keys(); + while (itr.hasNext()) { + KeyType currentKey = itr.next(); + if (!other.contains(currentKey)) { + result.add(currentKey); + } + } + return result; + } + + /** + * Retrieves a collection of all the keys in this set. + * + * @return a collection of all keys in this set + */ + @Override + public Iterable keys() { + return null; + } +} From 029e629b06aa223555ed2a8fa09cc9801f32c124 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Tue, 14 Mar 2023 10:11:50 -0700 Subject: [PATCH 3/6] BSTSet now working utilizing private helper methods coded as a class. --- src/FlightRoutesGraph.java | 77 +++++++++++++ src/Main.java | 53 ++++++++- src/edu/greenriver/sdev333/BSTSet.java | 144 ++++++++++++++++++++++--- 3 files changed, 261 insertions(+), 13 deletions(-) create mode 100644 src/FlightRoutesGraph.java diff --git a/src/FlightRoutesGraph.java b/src/FlightRoutesGraph.java new file mode 100644 index 0000000..51c3a88 --- /dev/null +++ b/src/FlightRoutesGraph.java @@ -0,0 +1,77 @@ +//import edu.greenriver.sdev333.BSTSet; +//import edu.greenriver.sdev333.MathSet; +// +//import java.util.HashSet; +// +//public class FlightRoutesGraph { +// // two sets needed to model a graph (network) +// // 1. a set of vertices (points, nodes) - airports +// // 2. a set of edges (connections, lines, relationships) +// // ^ route between airports +// +// private class Edge { +// private String node1; +// private String node2; +// +// public Edge(String from, String to) { +// node1 = from; +// node2 = to; +// } +// } +// +// private MathSet nodes; +// private MathSet edges; +// +// public FlightRoutesGraph() { +// nodes = new BSTSet<>(); // ok here b/c strings are comparable +// edges = new HashSet<>(); // must use HashSet b/c edges are not comparable +// } +// +// public void addNode(String city) { +// nodes.add(city); +// } +// +// public void addEdge(String city1, String city2) { +// Edge connection = new Edge(city1, city2); +// edges.add(connection); +// } +// +// MathSet getNeighbors(String city) { +// MathSet neighbors = new BSTSet<>(); +// +// // loop through the edges and check +// // if the city is either in node1 or node2 +// for (Edge e : edges.keys()) { +// if (e.node1.equals(city)) { +// neighbors.add(e.node2); +// } +// else if (e.node2.equals(city)) { +// neighbors.add(e.node1); +// } +// } +// return neighbors; +// } +// +// +// public static void main(String[] args) { +// FlightRoutesGraph g = new FlightRoutesGraph(); +// +// // add all the cities first (nodes) +// g.addNode("JFK"); +// g.addNode("ATL"); +// g.addNode("HOU"); +// g.addNode("ORD"); +// g.addNode("DEN"); +// +// +// // add connections between cities +// g.addEdge("JFK" , "MCO"); +// g.addEdge("ATL" , "MCO"); +// g.addEdge("DEN" , "ORD"); +// g.addEdge("ORD" , "ATL"); +// +// MathSet directFROMJFK = g.getNeighbors("JFK"); +// MathSet directFromATL = g.getNeighbors("ATL"); +// +// } +//} diff --git a/src/Main.java b/src/Main.java index 3e59c38..d2569e3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,56 @@ +import edu.greenriver.sdev333.BSTSet; +import edu.greenriver.sdev333.MathSet; + public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + + System.out.println("BSTSet tests:"); + BSTSet firstSet = new BSTSet(); + BSTSet secondSet = new BSTSet(); + + System.out.println("isEmpty before adding to set: " + firstSet.isEmpty()); + firstSet.add("a"); + firstSet.add("b"); + firstSet.add("c"); + firstSet.add("d"); + secondSet.add("a"); + secondSet.add("e"); + secondSet.add("f"); + secondSet.add("g"); + secondSet.add("h"); + System.out.println("Size after adding to firstSet = " + firstSet.size()); + + + // display each key in BST sets + System.out.println("isEmpty after adding string to set: " + firstSet.isEmpty()); + System.out.println("Iterable test - print each key in sets with forEach loop"); + for (String str : firstSet.keys()) { + System.out.println(str); + } + System.out.println("Second set keys:"); + for (String str : secondSet.keys()) { + System.out.println(str); + } + + // Union testing + System.out.println("Union:"); + MathSet unionSet = firstSet.union(secondSet); + for (String str : unionSet.keys()) { + System.out.println(str); + } + // Intersection testing + System.out.println("Intersection:"); + MathSet intersectionSet = firstSet.intersection(secondSet); + for (String str : intersectionSet.keys()) { + System.out.println(str); + } + // Difference testing + System.out.println("Difference:"); + MathSet differenceSet = firstSet.difference(secondSet); + for (String str : differenceSet.keys()) { + System.out.println(str); + } + + } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/BSTSet.java b/src/edu/greenriver/sdev333/BSTSet.java index 9404b00..41e710e 100644 --- a/src/edu/greenriver/sdev333/BSTSet.java +++ b/src/edu/greenriver/sdev333/BSTSet.java @@ -2,8 +2,14 @@ import java.util.Iterator; +/** + * Kevin Stone + * SDEV333: Final Project Part 1 - Implementing a Set + * + */ public class BSTSet> implements MathSet { + // private helper class used throughout class private class Node { private KeyType key; private Node left; @@ -16,7 +22,7 @@ public Node(KeyType key, int N) { } } - // field + // private field private Node root; /** @@ -26,7 +32,42 @@ public Node(KeyType key, int N) { */ @Override public void add(KeyType key) { + // starts the recursion + root = addNode(root, key); + } + + // private helper method used in class + // however, Sets do not utilize values - only keys + private Node addNode(Node current, KeyType key){ + // current is the root of the subtree we are looking at + // we are now at where we are supposed to be + if(current == null) { + // create a new node + return new Node(key, 1); + } + int cmp = key.compareTo(current.key); + // cmp will be -1 if key < currrent.key + // cmp will be 0 if key == current.key + // cmp will be 1 if key > currrent.key + + // we need to go left + if(cmp < 0) { + current.left = addNode(current.left, key); + } + // we need to go right + else if(cmp > 0) { + current.right = addNode(current.right, key); + } + else { + // key already exists in the set + current.key = key; + } + + // update the node's N - number of nodes in the subtree + // size of my left + size of my right + myself + current.N = size(current.left) + size(current.right) + 1; + return current; } /** @@ -37,6 +78,30 @@ public void add(KeyType key) { */ @Override public boolean contains(KeyType key) { + + // start at beginning, and look at each node's + // left and right + Node current = root; + while (current != null) { + int cmp = key.compareTo(current.key); + // cmp will be -1 if key < currrent.key + // cmp will be 0 if key == current.key + // cmp will be 1 if key > currrent.key + + // we need to go left + if(cmp < 0) { + current = current.left; + } + // we need to go right + else if(cmp > 0) { + current = current.right; + } + else { + // key already exists in the set + return true; + } + + } return false; } @@ -47,7 +112,7 @@ public boolean contains(KeyType key) { */ @Override public boolean isEmpty() { - return false; + return root == null; } /** @@ -57,7 +122,18 @@ public boolean isEmpty() { */ @Override public int size() { - return 0; + + return size(root); + } + + // private helper method used in class + private int size(Node current) { + if (current == null) { + return 0; + } + else { + return size(current.left) + size(current.right) + 1; + } } /** @@ -71,7 +147,23 @@ public int size() { */ @Override public MathSet union(MathSet other) { - return null; + + // create an empty set to return + MathSet result = new BSTSet(); + + // add each key to result set, then check the "otherSet" + // for new keys to add + for (KeyType key : this.keys()) { + result.add(key); + } + + // if key in "otherSet" is not in our resultSet - add to resultSet + for (KeyType currentKey : other.keys()) { + if (!result.contains(currentKey)) { + result.add(currentKey); + } + } + return result; } /** @@ -85,7 +177,16 @@ public MathSet union(MathSet other) { */ @Override public MathSet intersection(MathSet other) { - return null; + // create an empty set to return + MathSet result = new BSTSet(); + + // if our "otherSet" contains a key from our currentSet - add key to resultSet + for(KeyType currentKey : this.keys()){ + if(other.contains(currentKey)) { + result.add(currentKey); + } + } + return result; } /** @@ -99,14 +200,12 @@ public MathSet intersection(MathSet other) { */ @Override public MathSet difference(MathSet other) { - // create an empty set that will hold the result + // create an empty set to return MathSet result = new BSTSet(); - // iterate through all of the items in this - Iterator itr = (Iterator) this.keys(); - while (itr.hasNext()) { - KeyType currentKey = itr.next(); - if (!other.contains(currentKey)) { + // if key in setA (currentSet) is NOT in setB (otherSet) - add to resultSet + for(KeyType currentKey : this.keys()){ + if(!other.contains(currentKey)){ result.add(currentKey); } } @@ -120,6 +219,27 @@ public MathSet difference(MathSet other) { */ @Override public Iterable keys() { - return null; + + // create a new empty queue to hold my results + Queue keyQueue = new Queue<>(); + + // start the recursion, collecting results in the queue + inorder(root, keyQueue); + + // when done, return the queue + return keyQueue; + } + + // private helper method used in class, using provided Queue class + private void inorder(Node current, Queue q){ + if(current == null) { + // do nothing - end the method + return; + } + + inorder(current.left, q); + q.enqueue(current.key); + inorder(current.right, q); + } } From 369abb216d8a40497cf90c549e242bcf64145711 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Wed, 15 Mar 2023 16:46:17 -0700 Subject: [PATCH 4/6] Add now working in SeparateChainingHashTable class --- src/FlightRoutesGraph.java | 155 +++++++++--------- src/Main.java | 5 +- .../sdev333/SequentialSearchST.java | 66 ++++++++ 3 files changed, 147 insertions(+), 79 deletions(-) create mode 100644 src/edu/greenriver/sdev333/SequentialSearchST.java diff --git a/src/FlightRoutesGraph.java b/src/FlightRoutesGraph.java index 51c3a88..5620536 100644 --- a/src/FlightRoutesGraph.java +++ b/src/FlightRoutesGraph.java @@ -1,77 +1,78 @@ -//import edu.greenriver.sdev333.BSTSet; -//import edu.greenriver.sdev333.MathSet; -// -//import java.util.HashSet; -// -//public class FlightRoutesGraph { -// // two sets needed to model a graph (network) -// // 1. a set of vertices (points, nodes) - airports -// // 2. a set of edges (connections, lines, relationships) -// // ^ route between airports -// -// private class Edge { -// private String node1; -// private String node2; -// -// public Edge(String from, String to) { -// node1 = from; -// node2 = to; -// } -// } -// -// private MathSet nodes; -// private MathSet edges; -// -// public FlightRoutesGraph() { -// nodes = new BSTSet<>(); // ok here b/c strings are comparable -// edges = new HashSet<>(); // must use HashSet b/c edges are not comparable -// } -// -// public void addNode(String city) { -// nodes.add(city); -// } -// -// public void addEdge(String city1, String city2) { -// Edge connection = new Edge(city1, city2); -// edges.add(connection); -// } -// -// MathSet getNeighbors(String city) { -// MathSet neighbors = new BSTSet<>(); -// -// // loop through the edges and check -// // if the city is either in node1 or node2 -// for (Edge e : edges.keys()) { -// if (e.node1.equals(city)) { -// neighbors.add(e.node2); -// } -// else if (e.node2.equals(city)) { -// neighbors.add(e.node1); -// } -// } -// return neighbors; -// } -// -// -// public static void main(String[] args) { -// FlightRoutesGraph g = new FlightRoutesGraph(); -// -// // add all the cities first (nodes) -// g.addNode("JFK"); -// g.addNode("ATL"); -// g.addNode("HOU"); -// g.addNode("ORD"); -// g.addNode("DEN"); -// -// -// // add connections between cities -// g.addEdge("JFK" , "MCO"); -// g.addEdge("ATL" , "MCO"); -// g.addEdge("DEN" , "ORD"); -// g.addEdge("ORD" , "ATL"); -// -// MathSet directFROMJFK = g.getNeighbors("JFK"); -// MathSet directFromATL = g.getNeighbors("ATL"); -// -// } -//} +import edu.greenriver.sdev333.BSTSet; +import edu.greenriver.sdev333.MathSet; +import edu.greenriver.sdev333.SeparateChainingHashTable; + +import java.util.HashSet; + +public class FlightRoutesGraph { + // two sets needed to model a graph (network) + // 1. a set of vertices (points, nodes) - airports + // 2. a set of edges (connections, lines, relationships) + // ^ route between airports + + private class Edge { + private String node1; + private String node2; + + public Edge(String from, String to) { + node1 = from; + node2 = to; + } + } + + private MathSet nodes; + private MathSet edges; + + public FlightRoutesGraph() { + nodes = new BSTSet<>(); // ok here b/c strings are comparable + edges = new SeparateChainingHashTable<>(); // must use HashSet b/c edges are not comparable + } + + public void addNode(String city) { + nodes.add(city); + } + + public void addEdge(String city1, String city2) { + Edge connection = new Edge(city1, city2); + edges.add(connection); + } + + MathSet getNeighbors(String city) { + MathSet neighbors = new BSTSet<>(); + + // loop through the edges and check + // if the city is either in node1 or node2 + for (Edge e : edges.keys()) { + if (e.node1.equals(city)) { + neighbors.add(e.node2); + } + else if (e.node2.equals(city)) { + neighbors.add(e.node1); + } + } + return neighbors; + } + + + public static void main(String[] args) { + FlightRoutesGraph g = new FlightRoutesGraph(); + + // add all the cities first (nodes) + g.addNode("JFK"); + g.addNode("ATL"); + g.addNode("HOU"); + g.addNode("ORD"); + g.addNode("DEN"); + + + // add connections between cities + g.addEdge("JFK" , "MCO"); + g.addEdge("ATL" , "MCO"); + g.addEdge("DEN" , "ORD"); + g.addEdge("ORD" , "ATL"); + + MathSet directFROMJFK = g.getNeighbors("JFK"); + MathSet directFromATL = g.getNeighbors("ATL"); + + } +} diff --git a/src/Main.java b/src/Main.java index d2569e3..6895ee3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,12 +1,13 @@ import edu.greenriver.sdev333.BSTSet; import edu.greenriver.sdev333.MathSet; +import edu.greenriver.sdev333.SeparateChainingHashTable; public class Main { public static void main(String[] args) { System.out.println("BSTSet tests:"); - BSTSet firstSet = new BSTSet(); - BSTSet secondSet = new BSTSet(); + SeparateChainingHashTable firstSet = new SeparateChainingHashTable(); + SeparateChainingHashTable secondSet = new SeparateChainingHashTable(); System.out.println("isEmpty before adding to set: " + firstSet.isEmpty()); firstSet.add("a"); diff --git a/src/edu/greenriver/sdev333/SequentialSearchST.java b/src/edu/greenriver/sdev333/SequentialSearchST.java new file mode 100644 index 0000000..a16180f --- /dev/null +++ b/src/edu/greenriver/sdev333/SequentialSearchST.java @@ -0,0 +1,66 @@ +package edu.greenriver.sdev333; + +/** + * + */ +public class SequentialSearchST { + + // private field + private Node first; + private int size; + + // private helper class + private class Node { + // linked list node + KeyType key; + Node next; + public Node(KeyType key, Node next) { + this.key = key; + this.next = next; + } + } + + public void put(KeyType key) { + + for(Node x = first; x != null; x = x.next ){ + if(key.equals(x.key)){ + x.key = key; + return; + } + } + first = new Node(key, first); + size++; + } + + /** + * Gets the value of the key passed as a parameter + * @param key + * @return the associated value of the given key + */ + public KeyType get(KeyType key) { + + for(Node x = first; x != null; x = x.next){ + if(key.equals(x.key)){ + return x.key; + } + } + return null; + } + + public int size() { + + return 0; + } + + public Iterable keys() { + + Queue keyQueue = new Queue<>(); + + Node current = first; + while(current != null) { + keyQueue.enqueue(current.key); + current = current.next; + } + return keyQueue; + } +} From d048d438c6bf69fd2e6e38376ad033dd7072107b Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Wed, 15 Mar 2023 17:00:40 -0700 Subject: [PATCH 5/6] SeparateChainingHashTable finished using previous class completed with Ken --- .idea/uiDesigner.xml | 124 +++++++++++ .idea/vcs.xml | 6 + .../FinalProject/FlightRoutesGraph$Edge.class | Bin 0 -> 608 bytes .../FinalProject/FlightRoutesGraph.class | Bin 0 -> 2448 bytes out/production/FinalProject/Main.class | Bin 0 -> 3016 bytes .../edu/greenriver/sdev333/BSTSet$Node.class | Bin 0 -> 840 bytes .../edu/greenriver/sdev333/BSTSet.class | Bin 0 -> 4749 bytes .../edu/greenriver/sdev333/MathSet.class | Bin 0 -> 687 bytes .../sdev333/Queue$LinkedListIterator.class | Bin 0 -> 1322 bytes .../edu/greenriver/sdev333/Queue$Node.class | Bin 0 -> 673 bytes .../edu/greenriver/sdev333/Queue.class | Bin 0 -> 1943 bytes .../sdev333/SeparateChainingHashTable.class | Bin 0 -> 3968 bytes .../sdev333/SequentialSearchST$Node.class | Bin 0 -> 991 bytes .../sdev333/SequentialSearchST.class | Bin 0 -> 2079 bytes src/Main.java | 6 +- .../sdev333/SeparateChainingHashTable.java | 192 ++++++++++++++++++ .../sdev333/SequentialSearchST.java | 2 +- 17 files changed, 326 insertions(+), 4 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 out/production/FinalProject/FlightRoutesGraph$Edge.class create mode 100644 out/production/FinalProject/FlightRoutesGraph.class create mode 100644 out/production/FinalProject/Main.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/BSTSet$Node.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/BSTSet.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/MathSet.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/Queue$LinkedListIterator.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/Queue$Node.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/Queue.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/SeparateChainingHashTable.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/SequentialSearchST$Node.class create mode 100644 out/production/FinalProject/edu/greenriver/sdev333/SequentialSearchST.class create mode 100644 src/edu/greenriver/sdev333/SeparateChainingHashTable.java diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/FinalProject/FlightRoutesGraph$Edge.class b/out/production/FinalProject/FlightRoutesGraph$Edge.class new file mode 100644 index 0000000000000000000000000000000000000000..f213f5638023f94a355e8b6ac1239e8c44bb79ae GIT binary patch literal 608 zcmZuu$xZ@65PdZat0TL(3n~Y|-J_@%;+7Ci#BekjpoJmBjG1ZtFAv1TgCF2W8LKBo z4`Vv1dR1MoUi$Ut*ZT*6Gi)cJArgmfAc`2FbZJ||k-T@OQutS%`8=v#42FUblOxNo z9uf-e&`2|d1d?&249vkGWXI-(^Kn7Vt)Nu#m zh>&mpkvh_|oMBUq=V!~2bFtDV_`<^^^LeQj3NOjz)*B6(T+81_lU%ifyxD~#Cb|S(572(XTG18PRKsKwsjcejFha$%Xt{(Yb=Ui;;%s`Dd z#2dRa%s2LC$h`*a632WnlS7hGn)el$zsUUx>o6BfSmvzI3TtTrT4faBv&NN%b!-H= Oj7`odR@YF*7PN0*!+~l5 literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/FlightRoutesGraph.class b/out/production/FinalProject/FlightRoutesGraph.class new file mode 100644 index 0000000000000000000000000000000000000000..886fb5611a3ce5ff9925eb934476f306e801f577 GIT binary patch literal 2448 zcmbVN*>V#{6g@4Ckt~e?3lN(jKv*oxAg~P~7MMj?7|;?d+k_6?&*8aJ>B!$-#`BX;4+qD2q7GSVWJ1y z1a>~PmaI(Ea_X7#{8L%=1h!qW9ow4_2oI*_B8UnclC@5z?n>#n_L6in?V4N~9UaYF zugp}W7efT$Uc_NW&}U*hb_n$6n|8h7O}9FpY~OUP#fCtS)2hj~z>&fha7D{&5HA}+ zzrfioHdW-JV;{wJrxlF#2gQ*R^w>;^pbhB}s#Hk1dO{6d+kXVm*b&EjMR=d5Hy8)%++0BgJ z!g-<$<8%aPOk{9&73G610+EK*F3A^^1{Lu@d5oAC#TX-W^z`lzBJ_2X?Ij@>OniZh zLFvyCenTPw2{DX=6~AOsoYdR~J^CA{NBO*CHA%##MR}mkxoYCt+BqXJYB3ze4aR#r ze@Bh-CT?PinXtGes_-MMAe7Wx6u0SgZKe=KfyPvMHi{CB^7M@;zM^qsvJ}NMjbg5> zfM-n1V$KIvDiAoeQ91unXyyI2iTijUVAiEqlDshUEth$YZ32<{)TI&Vt=M(P@;WY~ z82iNbOWlQ-$WpkUbnDW!7JpVb8#&GFj)LvTQfFaay82$Ks<*0EbIx*YCEQ@r@ESIA z-L=V0Ayn1&mMI(6Q8v0C5r|b=j>9*~ZaD(`x;_0^1OyrAb=C<@ei*>=;%X3m70;?Z zD_V;|P*eYd`7Nk47Wh7?Yxl65>J$}YSZ-bAzsWKas0;MfY?ry_r^`jEczx`)7AR1X zQE7GDs?6I>X50NJol) zP>&vQ%!hPs{0$#B)&kque#;$q5vBzk9C`~ew1UX}x9EM17|oqD6R)xBCk^x++XM`@ z2iP7YMI5uL5$HWn4})Z0~k7? zii-pi>Usu%PZ+xjBDsQr`$OsBw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git a/out/production/FinalProject/edu/greenriver/sdev333/BSTSet$Node.class b/out/production/FinalProject/edu/greenriver/sdev333/BSTSet$Node.class new file mode 100644 index 0000000000000000000000000000000000000000..9585dbec6318c9de02977edfc00f910604ffb028 GIT binary patch literal 840 zcmaJv6#i~0gR*Wz!0A-noXi25)r2R*+=C=WBEbg;?**=`vul^zLc;!)55&X= ze}F&A_}#K#G^S13)9>8xob#P??$2M}e*k!kh6Mwe984QoYzZ98>D-wqDFfv#q;jIE zT(nv(=iOj9ka4XaPNl$BeCb8C*8+#VRC>FBJggiFHnw346tCQc>-cUkb3To)DV}%i;1ywgpUIerBOsy40jIvYm9=`6ltjnVtnBvdWuXvcQ{qdT9Iqt#lhBYV0I) z-RpUQ?9Z>qQVn&V0;OI!as832JdN+1rXIhZ&0lBi_U?SAzEPQEFAT!Dn#lK_&bYna z`Q9 z1|JYV`Ui7?K(VN=9%Hyi-jm1VJt4ZKHEAo&mn(?oH{_bHR@iA)SGf0;{tT-8mJ&`G z7BlU#a+!6X(tpHr#^R6_^;1c-8Ofinnjr&;#x?7JXwA~P*Bv|~>zG~x&rwV42~KGX L)M?-Zbr`<^**vlh literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/edu/greenriver/sdev333/BSTSet.class b/out/production/FinalProject/edu/greenriver/sdev333/BSTSet.class new file mode 100644 index 0000000000000000000000000000000000000000..503a3b223f49ef7f808f794ff8a951a96e7660e4 GIT binary patch literal 4749 zcmc&%-ESP#760Ac+01%(?8LE26O%X&agDvZi6N$xcwILiIK{;_7#o)aXm-4w*pt}1 z&VB>}1^PkZUx11t(W>|*47yo|$X8^v0R}+XJYQnG(!#0H-=j}^&|Ds)(?|)?Wypyje zY#VY5Ze>^@+S@nNggBZ^BrGIhDeQCRs{QjN$0?NDOHQf3Jm*{*7#Qe3F*QBqP}e9G ziyXSgHkIq1D9$*GLwr^B6JYeB2iI%bGoU6z}w}sEkLagM@FI0s1yDjvhk0NFFIkJBD z765g`wDq)w3=S!%3I0aKS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*H=kec9{_L(rv_vgoS_%kLxm`n2vOO-hhd}9us@Ykk9P5EWu`7m>>p&rcve~=Es25E!p$hIqYA&Sz$Lpu% z7X%IAU%yUuL`_YLaMl-Zq)VX9AQwn6kqoZP&i{ir*17@)kLyI5=_swWdW*F*laLyf zPu?ZpEqP)vK!wt!NwO~(ksUSDT5z*X<-9*ehr#);#Ik<9IXC%YL1Pw{)B1VEpwyiN z%EcQojx(C4U60euGaz?qMF0vEeh%`44MLd&7on8mP2$V21@V$>!%lKmU^nIW=zf0% VAFSXi)YAGx>M`qd1jk9olW*pStgrw8 literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/edu/greenriver/sdev333/Queue$LinkedListIterator.class b/out/production/FinalProject/edu/greenriver/sdev333/Queue$LinkedListIterator.class new file mode 100644 index 0000000000000000000000000000000000000000..ed71de1e13814dd116ea78b52442b84a33b4ba2c GIT binary patch literal 1322 zcmaJ=-A@xi5dUp^aBaDkTE0{eL8|scIiP-~Kuk!CB(=uS^uegfwq46Yxstm*qJNPu zK4?;6;)9Pq_(vIM@0viZxre*inVtE~{AOl<|M~F~zz&`!5kuUBVPOK347TX_cGnfc zapjqCZLcHFDwT@;+84ga*Q9eSIyLF3eI;D3`YywyI+R|1gJHQA6jZ`)J}MI{ z#Gfq`$7evqCH0FTbyJw>e0HYUJulVnUUC7oC4X~u9X zo7HcU&T+C$VU7NI(wc!MkSmqX!Ajp@mdXR9&oT2Y@V!m{48;I%k;FTCKkspeG>hUX z3U^T;SsbyHNMk7D-Y`dlr1nmi2AKH;)A$S{{)G$%H2h?6*}4Rq9)r~u4SS!y3B;zJ zX~bo$Q}vp~$&kgI&M=_uDTRk6;!*xe4)GvUNTf?GI>ZcQka3XOe1h0t+~z6g literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/edu/greenriver/sdev333/Queue$Node.class b/out/production/FinalProject/edu/greenriver/sdev333/Queue$Node.class new file mode 100644 index 0000000000000000000000000000000000000000..8ec58ca15aace75b621cf0da7641dc7a86187dec GIT binary patch literal 673 zcmaJzrHUts_b7o1`vsr*P?7FlZzB~~ZREwUu)n%xbKsl3*P*(G=Z>#3d$~#Jx z&@GKXcRTPU)iW*Xd&@D|Lpffs&`fVNk&BVEO&@O-Ro^~=+;)wJ+0?bc%CjfbG5ro& zV0_ItL?GTL$GuxQZVW|%e3QXbr?lBYt`#Fi0V6HuZ$GrI7XQR<{oj>gMSUj+!Hw2TFEj} VaLO@)GvtF@z&U3vIIZBT`~fJAo4^17 literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/edu/greenriver/sdev333/Queue.class b/out/production/FinalProject/edu/greenriver/sdev333/Queue.class new file mode 100644 index 0000000000000000000000000000000000000000..001fb4bce423e126583b2e3fc9ad556b369e4476 GIT binary patch literal 1943 zcmah}U2hXt5Ixr)S=(8MU`!xsLJ0}fUema(X$#ndv}vFQCkQ2qM4#Bix9NhjPIuQ) z=|Aa1pLyv+E0IY3f8c4Fi{c<;S)XU?26GuQvT`SULTw{SOy1d;|) zCej#Fn0#U%+SQKj?o}V`Jkh&>!dSy`onToZSt@U5kwMl#&crxOg<0M1RrfrtUC%kx zUe#~w!&)YxLw{?@YtU0+@bYfD+Htg*r=rqvt0{T=OX*&%G9)!nr_+qUP(IX0$( z?;Ky@!pJmrg{kAg%oqb$BO?b15+%PG*t<{H?SnX&bJk=~`8RFABN7aH5v_C-FAgI>sxO%EN#PW~tndP{N}3iMJ{}6OENMF;~Ux!*0uDP{WF`ctG!hg z$JacjWENz!hei+c9OVQQK0uNypEmbp{y`*Q@y9oL?93<0yD{4MpTTd1r^jJDP_+Jl zveXd_`Q)wS5hj1*eG*ssoni!V9w|&Ciy2Jt(Vf98KBQH0Fdj>&a{cI-$ZY;#v zwz!IS-g*J!Zy2fPNF{%vAr+<(QlN7mHa`R_7J>bQzcdo#D}q=+jbG981y=z{GsC1H zM*m`bhSg0wf5Dk?hOv}oO%~`+W;!l{c zUQn4%&uTe8lG~zkAL6@6M7s>sZsS8!-qDv>Msu?K_f)?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& z2h&I!sxnzAd9Q7~ zN2CUF6mnIS-fS$xp;Upk@0^zIqCoB6Judxj|7~+sRDLpR7omBT{8_5T^d`_;>g!|G z(Tx=-_9;%@&ElkhmjbQaqb11Uxmw#rol&=(pR=~dUV|fEWbyzFmL+Cv J-~fj({s4#d_3;1z literal 0 HcmV?d00001 diff --git a/out/production/FinalProject/edu/greenriver/sdev333/SequentialSearchST.class b/out/production/FinalProject/edu/greenriver/sdev333/SequentialSearchST.class new file mode 100644 index 0000000000000000000000000000000000000000..504d052e20d0d917d64d58a01159386cdf365b4f GIT binary patch literal 2079 zcmb7ETW=Fb7(L?)Ynyd|#F!>=04H30No}YpZL#A50jj7@5ONeLJaywt!-BgB>)nX- zpY#`0m0Ag;q>+l$$3F1Hub_{8uehD@ZhWajWgd2}=lk}Y^UchQw}1QzU=H8J5I|5v zNJkh)1dcy6wvA%bur`W!*B;7-BXFc*TBcJK2xhV?QA7~c5YurKxsbeu$zD#_SrwggUQ27%f8io+*5#+B%hC7(DkE=(%ZQUY6< z;U$#^vkxEa`QcUJw2m`4OExX@M=2l{G)xPmK48v0SGqEWG=i!*uj2wP3TV<|om_?= zs(M8rS~oW=!*Ok5%EJ?_EPpF^mUp&fxmsw~kUZyEOMzoG(~?W>4{Oq1HrAS48Le$L zjOL1An`-VahMWf`i;*Axmt}!uen^}4m+>i{qaM(E-EWSXZC%Th|Su)uLy2i6hACj4DPw0XpZRHgSM!4Uut-$FI ziEQr^t2JEP=B?zl{aG( zcU9o%l59DPQXLkWpf6aKwC9^ft0g%Nse{GC9N{enzkqs@AdqR#vYhjNa2)0u-!`^6 z&Tg<5YBjeH@r;8Y@@&<%YG>K1Br5Dv6xbL0RxWWSa2XewUZs1~OVZWr3(>|aRb zXLk|*9b-QsI-B1^{2Aw`7Jq*CD)$^CtGT=a?qgyPT5fe0Q=#wnFr|2e+B~Ky2YhCt zm_P!P9HlrK$27&1C})m>700vuYZz1bjBJ(ss?S!9_)3za;@w3lJ3N$9;Gs%HUEx?q z@HN63MiT!*^X>bbdsp#=uksi6O6AOf%E_+Eh|>Gi7x}k%N|+}lNrIqBQ3^|t^fgXUnBYMH8AX^TjtcqD(UB@0x!!Sv2KzolSo#VPd~1*- zN)`E_pdL#3;Gw?mpp;8qK?83P*N|pS$NYj`XH~qLaRWCQ8^Annu@5nN1h+YgwMP-$ GLEt?aq`&3> literal 0 HcmV?d00001 diff --git a/src/Main.java b/src/Main.java index 6895ee3..e5f6c46 100644 --- a/src/Main.java +++ b/src/Main.java @@ -9,7 +9,7 @@ public static void main(String[] args) { SeparateChainingHashTable firstSet = new SeparateChainingHashTable(); SeparateChainingHashTable secondSet = new SeparateChainingHashTable(); - System.out.println("isEmpty before adding to set: " + firstSet.isEmpty()); + System.out.println("isEmpty before adding to firstSet: " + firstSet.isEmpty()); firstSet.add("a"); firstSet.add("b"); firstSet.add("c"); @@ -23,8 +23,8 @@ public static void main(String[] args) { // display each key in BST sets - System.out.println("isEmpty after adding string to set: " + firstSet.isEmpty()); - System.out.println("Iterable test - print each key in sets with forEach loop"); + System.out.println("isEmpty after adding string to set: " + firstSet.isEmpty() + " Size is now: " + firstSet.size()); + System.out.println("Iterable test - print each key in firstSet with forEach loop"); for (String str : firstSet.keys()) { System.out.println(str); } diff --git a/src/edu/greenriver/sdev333/SeparateChainingHashTable.java b/src/edu/greenriver/sdev333/SeparateChainingHashTable.java new file mode 100644 index 0000000..cf53257 --- /dev/null +++ b/src/edu/greenriver/sdev333/SeparateChainingHashTable.java @@ -0,0 +1,192 @@ +package edu.greenriver.sdev333; +/** + * Kevin Stone + * SDEV333: Final Project Part 1 - Implementing a Set + * + * This class is to implement the MathSet interface. The + * SequentialSearchST class (created in-class with instructor + * Ken Hang) is used in this implementation. + */ +public class SeparateChainingHashTable implements MathSet { + // fields: + // array of linked lists - but we wrote a linked list in SequentialSearchSt + private SequentialSearchST[] st; + private int M; // M is the number of buckets + + // default constructor that calls our parameterized constructor + public SeparateChainingHashTable(){ + // default constructor + // calls the other constructor with a value + this(997); + } + + // constructor + public SeparateChainingHashTable(int M) { + // take their number of buckets and save them into the field + this.M = M; + + // create the array + st = new SequentialSearchST[M]; + + // for each position in the array, create a linked list (SequentialSearchSt) + for (int i = 0; i < M; i++) { + st[i] = new SequentialSearchST<>(); + } + } + + + /** + * Puts the specified key into the set. + * + * @param key key to be added into the set + */ + @Override + public void add(KeyType key) { + // use hash function to determine which index to add to + int indexToAddTo = hash(key); + // add here + st[indexToAddTo].put(key); + } + + // private helper method created in class to return an int + private int hash(KeyType key){ + // hash function = give me a key, I return an int (bucket#, array index) + return (key.hashCode() & 0x7fffffff ) % M; + } + + /** + * Is the key in the set? + * + * @param key key to check + * @return true if key is in the set, false otherwise + */ + @Override + public boolean contains(KeyType key) { + return get(key) != null; + } + + // method created in class (SequentialSearchST) + // return null if not found + public KeyType get(KeyType key) { + int index = hash(key); // find the bucket number + // go into the bucket and see if it's there + return st[index].get(key); + } + + /** + * Is the set empty? + * + * @return true if the set is empty, false otherwise + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Number of keys in the set + * + * @return number of keys in the set. + */ + @Override + public int size() { + // iterate through each "bucket"'s linkedList + // for each of these lists, call the size method used in + // SequentialSearchST + int size = 0; + for (int i = 0; i < M; i++) { + size += st[i].size(); + } + + return size; + } + + /** + * Determine the union of this set with another specified set. + * Returns A union B, where A is this set, B is other set. + * A union B = {key | A.contains(key) OR B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to union + * @return the union of this set with other + */ + @Override + public MathSet union(MathSet other) { + + MathSet result = new SeparateChainingHashTable(M); + + // add all current keys to resultSet + for (KeyType currentKey: this.keys()) { + result.add(currentKey); + } + // add all "other" keys to resultSet + for(KeyType currentKey : other.keys()){ + result.add(currentKey); + } + return result; + } + + /** + * Determine the intersection of this set with another specified set. + * Returns A intersect B, where A is this set, B is other set. + * A intersect B = {key | A.contains(key) AND B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to intersect + * @return the intersection of this set with other + */ + @Override + public MathSet intersection(MathSet other) { + + MathSet result = new SeparateChainingHashTable(M); + + // if our current key is also in our "other" keys, add to resultSet + for (KeyType currentKey: this.keys()) { + if(other.contains(currentKey)){ + result.add(currentKey); + } + } + return result; + } + + /** + * Determine the difference of this set with another specified set. + * Returns A difference B, where A is this set, B is other set. + * A difference B = {key | A.contains(key) AND !B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to difference + * @return the difference of this set with other + */ + @Override + public MathSet difference(MathSet other) { + + MathSet result = new SeparateChainingHashTable(M); + + // if our current key is not in our "other" keys, add to resultSet + for (KeyType currentKey: this.keys()) { + if(!other.contains(currentKey)){ + result.add(currentKey); + } + } + return result; + } + + /** + * Retrieves a collection of all the keys in this set. + * + * @return a collection of all keys in this set + */ + @Override + public Iterable keys() { + Queue collector = new Queue<>(); + // for every bucket + for (int i = 0; i < M; i++) { + // take each key in that bucket and add it into the collector + for (KeyType key : st[i].keys()) { + collector.enqueue(key); + } + } + return collector; + } +} diff --git a/src/edu/greenriver/sdev333/SequentialSearchST.java b/src/edu/greenriver/sdev333/SequentialSearchST.java index a16180f..a343ea8 100644 --- a/src/edu/greenriver/sdev333/SequentialSearchST.java +++ b/src/edu/greenriver/sdev333/SequentialSearchST.java @@ -49,7 +49,7 @@ public KeyType get(KeyType key) { public int size() { - return 0; + return size; } public Iterable keys() { From 57c11b65dcac922ee6eaccac17cc7b5bb8e6920a Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Wed, 15 Mar 2023 17:24:51 -0700 Subject: [PATCH 6/6] Added more comments --- src/edu/greenriver/sdev333/SeparateChainingHashTable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/edu/greenriver/sdev333/SeparateChainingHashTable.java b/src/edu/greenriver/sdev333/SeparateChainingHashTable.java index cf53257..927b2e9 100644 --- a/src/edu/greenriver/sdev333/SeparateChainingHashTable.java +++ b/src/edu/greenriver/sdev333/SeparateChainingHashTable.java @@ -65,7 +65,7 @@ public boolean contains(KeyType key) { return get(key) != null; } - // method created in class (SequentialSearchST) + // use method created in class (SequentialSearchST) // return null if not found public KeyType get(KeyType key) { int index = hash(key); // find the bucket number @@ -92,7 +92,7 @@ public boolean isEmpty() { public int size() { // iterate through each "bucket"'s linkedList // for each of these lists, call the size method used in - // SequentialSearchST + // SequentialSearchST ( <- every time we "put" a key - size is incremented ) int size = 0; for (int i = 0; i < M; i++) { size += st[i].size();