-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMiniCassandra.java
More file actions
45 lines (42 loc) · 1.43 KB
/
Copy pathMiniCassandra.java
File metadata and controls
45 lines (42 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package leetcode;
import java.util.*;
public class MiniCassandra {
HashMap<String,TreeMap<Integer,Column>> map;
public MiniCassandra() {
// initialize your data structure here.
this.map = new HashMap<String,TreeMap<Integer,Column>>();
}
/**
* @param raw_key a string
* @param column_start an integer
* @param column_end an integer
* @return void
*/
public void insert(String raw_key, int column_key, String column_value) {
// Write your code here
Column col = new Column(column_key,column_value);
if(this.map.containsKey(raw_key))
this.map.get(raw_key).put(column_key,col);
else{
TreeMap<Integer, Column> treeMap = new TreeMap<Integer, Column>();
treeMap.put(column_key, col);
this.map.put(raw_key,treeMap);
}
}
/**
* @param raw_key a string
* @param column_start an integer
* @param column_end an integer
* @return a list of Columns
*/
public List<Column> query(String raw_key, int column_start, int column_end) {
// Write your code here
ArrayList<Column> ret = new ArrayList<Column>();
if(!this.map.containsKey(raw_key))
return ret;
for(Map.Entry<Integer, Column> entry:this.map.get(raw_key).subMap(column_start, true, column_end, true).entrySet()){
ret.add(entry.getValue());
}
return ret;
}
}