Repository navigation
Expand file tree
/
Copy pathLongMap.java
More file actions
118 lines (101 loc) · 3.06 KB
/
Copy pathLongMap.java
File metadata and controls
118 lines (101 loc) · 3.06 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2012 Jan Kotek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapdb;
import java.util.Iterator;
/**
* Same as 'java.util.Map' but uses primitive 'long' keys to minimise boxing (and GC) overhead.
*
* @author Jan Kotek
*/
public abstract class LongMap<V> {
/**
* Removes all mappings from this hash map, leaving it empty.
*
* @see #isEmpty
* @see #size
*/
public abstract void clear();
/**
* Returns the value of the mapping with the specified key.
*
* @param key the key.
* @return the value of the mapping with the specified key, or {@code null}
* if no mapping for the specified key is found.
*/
public abstract V get(long key);
/**
* Returns whether this map is empty.
*
* @return {@code true} if this map has no elements, {@code false}
* otherwise.
* @see #size()
*/
public abstract boolean isEmpty();
/**
* Maps the specified key to the specified value.
*
* @param key the key.
* @param value the value.
* @return the value of any previous mapping with the specified key or
* {@code null} if there was no such mapping.
*/
public abstract V put(long key, V value);
/**
* Removes the mapping from this map
*
* @param key to remove
* @return value contained under this key, or null if value did not exist
*/
public abstract V remove(long key);
/**
* Returns the number of elements in this map.
*
* @return the number of elements in this map.
*/
public abstract int size();
/**
* @return iterator over values in map
*/
public abstract Iterator<V> valuesIterator();
public abstract LongMapIterator<V> longMapIterator();
/** Iterates over LongMap key and values without boxing long keys */
public interface LongMapIterator<V>{
boolean moveToNext();
long key();
V value();
void remove();
}
@Override
public String toString(){
final StringBuilder b = new StringBuilder();
b.append(getClass().getSimpleName());
b.append('[');
boolean first = true;
LongMapIterator<V> iter = longMapIterator();
while(iter.moveToNext()){
if(first){
first = false;
}else{
b.append(", ");
}
b.append(iter.key());
b.append(" => ");
b.append(iter.value());
}
b.append(']');
return b.toString();
}
}