File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ package search ;
2+
3+ /**
4+ * Created by Jbee on 2017. 6. 1..
5+ */
6+ public class BinarySearchTest {
7+ }
You can’t perform that action at this time.
0 commit comments