Commit f9928a88 authored by Adam Blank's avatar Adam Blank
Browse files

Initial commit

parents
No related merge requests found
Pipeline #77352 canceled with stage
Showing with 438 additions and 0 deletions
+438 -0
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
#.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
data/*
static:
script: /testers/cs2/project05/static/test
A:
script: /testers/cs2/project05/suite/test
B:
script: /testers/cs2/project05/suite/test
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="checkstyle-version" value="8.13" />
<entry key="copy-libs" value="false" />
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="scan-before-checkin" value="false" />
<entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" />
</map>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="com.github.javaparser:javaparser-core:3.5.12" type="repository">
<properties maven-id="com.github.javaparser:javaparser-core:3.5.12" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/javaparser/javaparser-core/3.5.12/javaparser-core-3.5.12.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
File added
<component name="libraryTable">
<library name="org.hamcrest:hamcrest:2.2" type="repository">
<properties maven-id="org.hamcrest:hamcrest:2.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.hamcrest:hamcrest-core:2.2" type="repository">
<properties maven-id="org.hamcrest:hamcrest-core:2.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/2.2/hamcrest-core-2.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.javassist:javassist:3.29.2-GA" type="repository">
<properties maven-id="org.javassist:javassist:3.29.2-GA" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.29.2-GA/javassist-3.29.2-GA.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.junit.jupiter:junit-jupiter:5.6.0-M1j" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.9.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.9.2/junit-jupiter-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.9.2/junit-jupiter-params-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PreferredVcsStorage">
<preferredVcsName>ApexVCS</preferredVcsName>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/project05-markov.iml" filepath="$PROJECT_DIR$/project05-markov.iml" />
</modules>
</component>
</project>
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="A Tests" type="JUnit" factoryName="JUnit">
<module name="project05-markov" />
<option name="ALTERNATIVE_JRE_PATH" value="17" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<option name="VM_PARAMETERS" value="-noverify -ea -javaagent:.idea/libraries/instrumentation.jar" />
<option name="PARAMETERS" value="" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<tag value="A" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="B Tests" type="JUnit" factoryName="JUnit">
<module name="project05-markov" />
<option name="ALTERNATIVE_JRE_PATH" value="17" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<option name="VM_PARAMETERS" value="-noverify -ea -javaagent:.idea/libraries/instrumentation.jar" />
<option name="PARAMETERS" value="" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<tag value="B" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ChainingHashDictionaryTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
<option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.ChainingHashDictionaryTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-noverify -ea -javaagent:.idea/libraries/instrumentation.jar" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MoveToFrontDictionaryTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
<option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MoveToFrontDictionaryTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-noverify -ea -javaagent:.idea/libraries/instrumentation.jar" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="NGramTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="ALTERNATIVE_JRE_PATH" value="19" />
<option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
<option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.NGramTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-noverify -ea -javaagent:.idea/libraries/instrumentation.jar" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="org.hamcrest:hamcrest:2.2" level="project" />
<orderEntry type="library" name="org.hamcrest:hamcrest-core:2.2" level="project" />
<orderEntry type="library" name="org.junit.jupiter:junit-jupiter:5.6.0-M1j" level="project" />
<orderEntry type="library" name="com.github.javaparser:javaparser-core:3.5.12" level="project" />
<orderEntry type="library" name="org.javassist:javassist:3.29.2-GA" level="project" />
</component>
</module>
\ No newline at end of file
package edu.caltech.cs2.datastructures;
import edu.caltech.cs2.interfaces.ICollection;
import edu.caltech.cs2.interfaces.IQueue;
import edu.caltech.cs2.interfaces.IDictionary;
import java.util.Iterator;
public class BSTDictionary<K extends Comparable<? super K>, V>
implements IDictionary<K, V> {
private BSTNode<K, V> root;
private int size;
/**
* Class representing an individual node in the Binary Search Tree
*/
private static class BSTNode<K, V> {
public final K key;
public V value;
public BSTNode<K, V> left;
public BSTNode<K, V> right;
/**
* Constructor initializes this node's key, value, and children
*/
public BSTNode(K key, V value) {
this.key = key;
this.value = value;
this.left = null;
this.right = null;
}
public BSTNode(BSTNode<K, V> o) {
this.key = o.key;
this.value = o.value;
this.left = o.left;
this.right = o.right;
}
public boolean isLeaf() {
return this.left == null && this.right == null;
}
public boolean hasBothChildren() {
return this.left != null && this.right != null;
}
}
/**
* Initializes an empty Binary Search Tree
*/
public BSTDictionary() {
this.root = null;
this.size = 0;
}
@Override
public V get(K key) {
return null;
}
@Override
public V remove(K key) {
return null;
}
@Override
public V put(K key, V value) {
return null;
}
@Override
public boolean containsKey(K key) {
return false;
}
@Override
public boolean containsValue(V value) {
return false;
}
/**
* @return number of key/value pairs in the BST
*/
@Override
public int size() {
return this.size;
}
@Override
public ICollection<K> keys() {
return null;
}
@Override
public ICollection<V> values() {
return null;
}
/**
* Implementation of an iterator over the BST
*/
@Override
public Iterator<K> iterator() {
return keys().iterator();
}
@Override
public String toString() {
if (this.root == null) {
return "{}";
}
StringBuilder contents = new StringBuilder();
IQueue<BSTNode<K, V>> nodes = new ArrayDeque<>();
BSTNode<K, V> current = this.root;
while (current != null) {
contents.append(current.key + ": " + current.value + ", ");
if (current.left != null) {
nodes.enqueue(current.left);
}
if (current.right != null) {
nodes.enqueue(current.right);
}
current = nodes.dequeue();
}
return "{" + contents.toString().substring(0, contents.length() - 2) + "}";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment