Add DB implementation

This commit is contained in:
Max O'Cull 2019-01-19 20:45:55 -05:00
parent a21b74e840
commit 0d2c72edc6
87 changed files with 29 additions and 6 deletions

View File

@ -7,8 +7,8 @@ INDEX VERSION 1.131+/home/max/src/cs448/p1/.metadata/.plugins/org.eclipse.jdt.co
116444480.index
3664742106.index
131124632.index
3842426239.index
2054031921.index
3842426239.index
629469267.index
1986281775.index
1844288107.index

Binary file not shown.

2
p1/run
View File

@ -1,3 +1,3 @@
#! /bin/bash
java -cp ./target/cs448p1-1.0-SNAPSHOT-jar-with-dependencies.jar -Xmx44m cs448.App "$1" "$2" "$3"
java -cp ./target/cs448p1-1.0-SNAPSHOT-jar-with-dependencies.jar -Xmx32m cs448.App "$1" "$2" "$3"

View File

@ -2,6 +2,7 @@ package cs448;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.Serializer;
import java.io.IOException;
import java.io.BufferedReader;
@ -20,7 +21,7 @@ public class project1 {
DB db = DBMaker.fileDB(dbfile).make();
// use this for MapDB storage
ConcurrentMap mapdb = db.hashMap("map").make();
ConcurrentMap<String, String> mapdb = db.hashMap("map", Serializer.STRING, Serializer.STRING).make();
void load_mainmemory(String file_path) throws IOException {
try (BufferedReader tsvFile = new BufferedReader(new FileReader(file_path))) {
@ -49,7 +50,29 @@ public class project1 {
}
void load_mapdb(String file_path) throws IOException{
/** Put your code here **/
try (BufferedReader tsvFile = new BufferedReader(new FileReader(file_path))) {
String line = "";
String value = "";
while ((line = tsvFile.readLine()) != null ) {
String[] parts = line.split("\t");
for (int i = 1; i < parts.length; i++) {
if (i == parts.length) {
value += parts[i];
} else {
value += parts[i] + "\t";
}
parts[i] = null;
}
mapdb.put(parts[0], value);
parts[0] = null;
line = null;
value = null;
}
} catch (IOException e) {
throw e;
}
}
String select_file(String key, String file_path) throws IOException{
@ -81,8 +104,8 @@ public class project1 {
String select_mainmemory(String key){
return mm_map.get(key);
}
String select_mapdb(String key){
/** Put your code here **/
return "";
return mapdb.get(key);
}
}