Final report packaged
This commit is contained in:
parent
df6fdad8e5
commit
d8ad2e4a6c
15
p1/report/README.txt
Normal file
15
p1/report/README.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
(a) What have you observed to be the fastest Load operation?
|
||||||
|
[X] Main-memory Load. [ ] MapDB Load
|
||||||
|
|
||||||
|
(b) Why do you think that load operation was faster?
|
||||||
|
Main memory is higher/faster on the memory hiearchy than disk.
|
||||||
|
|
||||||
|
(c) What have you observed to be the fastest Select operation?
|
||||||
|
[ ] File Select [X] Main-memory Select. [ ] MapDB Select
|
||||||
|
|
||||||
|
(d) Why do you think that select operation was faster?
|
||||||
|
Main memory is higher/faster on the memory hiearchy than disk.
|
||||||
|
|
||||||
|
(e) What are the benefits of using the embedded database as backend compare to the in-
|
||||||
|
memory storage?
|
||||||
|
Much more storage is available on disk via the embedded database than in main memory.
|
111
p1/report/project1.java
Normal file
111
p1/report/project1.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package cs448;
|
||||||
|
|
||||||
|
import org.mapdb.DB;
|
||||||
|
import org.mapdb.DBMaker;
|
||||||
|
import org.mapdb.Serializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
|
||||||
|
public class project1 {
|
||||||
|
|
||||||
|
/* Data structure for Main-memory back-end */
|
||||||
|
HashMap<String,String> mm_map = new HashMap<String,String>();
|
||||||
|
|
||||||
|
/* Data structure for MapDB persistent storage*/
|
||||||
|
String dbfile = "data.db";
|
||||||
|
DB db = DBMaker.fileDB(dbfile).make();
|
||||||
|
|
||||||
|
// use this for MapDB storage
|
||||||
|
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))) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_map.put(parts[0], value);
|
||||||
|
parts[0] = null;
|
||||||
|
line = null;
|
||||||
|
value = null;
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_mapdb(String file_path) throws IOException{
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mapdb.put(parts[0], value);
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String select_file(String key, String file_path) throws IOException{
|
||||||
|
try (BufferedReader tsvFile = new BufferedReader(new FileReader(file_path))) {
|
||||||
|
String line = "";
|
||||||
|
while ((line = tsvFile.readLine()) != null ) {
|
||||||
|
if(line.startsWith(key)) {
|
||||||
|
String[] parts = line.split("\t");
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
for (int i = 1; i < parts.length; i++) {
|
||||||
|
if (i == parts.length) {
|
||||||
|
result += parts[i];
|
||||||
|
} else {
|
||||||
|
result += parts[i] + "\t";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String select_mainmemory(String key){
|
||||||
|
return mm_map.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
String select_mapdb(String key){
|
||||||
|
String result = mapdb.get(key);
|
||||||
|
// db.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user