Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 19670fc

Browse filesBrowse files
committed
Add bit map code
1 parent 2ceb698 commit 19670fc
Copy full SHA for 19670fc

2 files changed

+51Lines changed: 51 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/test/java/bit/BitMapTest.java‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package bit;
2+
3+
import org.junit.Test;
4+
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.junit.Assert.assertThat;
7+
8+
public class BitMapTest {
9+
10+
/*
11+
TASK
12+
O(1)으로 해당 데이터가 존재하는지 판단한다.
13+
*/
14+
15+
@Test
16+
public void test() {
17+
BitMap bitMap = new BitMap();
18+
bitMap.store("1234567");
19+
assertThat(bitMap.exist("1234567"), is(true));
20+
assertThat(bitMap.exist("1234568"), is(false));
21+
}
22+
23+
public class BitMap {
24+
public int[] cache;
25+
26+
public BitMap() {
27+
cache = new int[(10 * 1000 * 1000) / 32];
28+
}
29+
30+
public void store(String data) {
31+
int dataInt = Integer.parseInt(data);
32+
int arrIndex = dataInt / 32;
33+
int byteIndex = dataInt % 32;
34+
cache[arrIndex] = cache[arrIndex] | (1 << byteIndex);
35+
}
36+
37+
public boolean exist(String data) {
38+
int dataInt = Integer.parseInt(data);
39+
int arrIndex = dataInt / 32;
40+
int byteIndex = dataInt % 32;
41+
return (cache[arrIndex] & (1 << byteIndex)) != 0;
42+
}
43+
}
44+
}
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package search;
2+
3+
/**
4+
* Created by Jbee on 2017. 6. 1..
5+
*/
6+
public class BinarySearchTest {
7+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.