HashTableList entry = table [hash];
APPENDIX
CODING HASHTABLE DATA STRUCTURE1. HashTableMain.java
1 package com.example.revan.hashtable_playstore.HashTableHitung ; 2 /** * Created by REVAN on 7/22/17.
3
- */
4 5 public class HashTableMain {
private int TABLE_SIZE ;
6
private int size ;
7
public HashTableList[] table ; //
8
public HashTableMain ( int ts) {
9
size = ;
10 TABLE_SIZE = ts ;
11
table = new HashTableList[ TABLE_SIZE ] ;
12
for ( int i = ; i < TABLE_SIZE ; i++)
13
table [i] = null; // looping table tapi masih
14
kosong }
15
public HashTableList[] getTable (){
16
return table ;
17
}
18
public int getTABLE_SIZE (){
19
return TABLE_SIZE ;
20
}
21
public void makeEmpty () {
22
for ( int i = ; i < TABLE_SIZE ; i++)
23
table [i] = null;
24
}
25
public void insertvalue ( int value)
26
{
27
int hash = (value % TABLE_SIZE ) ;
28
if ( table [hash] == null )
29
table [hash] = new HashTableList(value) ;
30
else
31
{
32 HashTableList entry = table [hash] ;
33
while (entry. next != null )
34
entry = entry. next ;
35
//while (entry.value == value)
36
//entry.value = value;
37
if (entry. value == value)
38
entry. value = value ;
39
else
40
entry. next = new HashTableList(value) ;
41
}
42
; ++ size
43
}
44
public int [] getLoc ( int value) {
45
int hash = (value % TABLE_SIZE ) ;
46
47
int [] notFound = { 100 , 100 } ;
48
int count = ;
49
if ( table [hash] != null ) {
50 HashTableList entry = table [hash] ;
51
result[ ] = hash ;
52
while (entry != null ) {
53
if (entry. value == value) {
54
result[ 1 ] = count ;
55
//Log.i("index2", String.valueOf(count));
56
break;
57
} else
58
count++ ;
59
entry = entry. next ;
60
}
61
return result ;
62
} else return notFound ;
63
}
64
public int [] getLoc2 ( int value) {
65
int hash = (value % TABLE_SIZE ) ;
66
int [] result = { 1000 , 1000 } ; //00
67
int [] notFound = { 100 , 100 } ;
68
int count = ;
69
if ( table [hash] != null ) {
70 HashTableList entry = table [hash] ;
71
while (entry != null ) {
72
if (entry. value == value) {
73
result[ ] = hash ;
74
result[ 1 ] = count ;
75
//Log.i("index2", String.valueOf(count));
76
break;
77
} else
78
count++ ;
79
entry = entry. next ;
80
}
81
return result ;
82
} else return notFound ;
83
}
84
public void removevalue ( int value) {
85
int hash = (value % TABLE_SIZE ) ;
86
if ( table [hash] != null ) {
87 HashTableList delEntry = null;
88 HashTableList entry = table [hash] ;
89
while (entry != null ) {
90
if (entry. value == value) {
91
if (entry == table [hash])
92
table [hash] = entry. next ;
93
else
94
delEntry. next = entry. next ; //atau
95
entry.next
; -- size
96
} else {
97
delEntry = entry ;
98
}
99 100
}
101
}
102
}
103
public void printHashTable ()
104
{
105
for ( int i = ; i < TABLE_SIZE ; i++)
106
{
107
HashTableList entry = table [i] ;
108
System. out .print( " \n ARRAY [" + (i) + "] : " ) ;
109
while (entry != null )
110
{
111
- + " ) ;
- + + System. out .print(entry. value " " "|" "
112
entry = entry. next ;
113
}
114
}
115
}
116 117 } 118
2. HashTableList.java
119 package com.example.revan.hashtable_playstore.HashTableHitung ; 120 /** * Created by REVAN on 7/22/17. 121
- */
122 123 public class HashTableList {
public int value ;
124
public HashTableList next ;
125
HashTableList ( int value)
126
{
127
this . value = value ;
128
this . next = null;
129
}
130 131 } 132
CODING DRAWING
2. MainActivity.java
private Button saveButton ;
private Button DeleteButton ;
173
private Button tampil ;
172
private Button hashButton ;
171
133 package com.example.revan.hashtable_playstore ; 134 import android.content.Context ; 135 import android.content.Intent ; 136 import android.content.SharedPreferences ; 137 import android.graphics.Bitmap ; 138 import android.graphics.Canvas ; 139 import android.graphics.Color ; 140 import android.graphics.Paint ; 141 import android.graphics.PorterDuff ; 142 import android.graphics.drawable.BitmapDrawable ; 143 import android.os.Build ; 144 import android.os.Bundle ; 145 import android.os.CountDownTimer ; 146 import android.support.annotation.RequiresApi ; 147 import android.support.design.widget.FloatingActionButton ; 148 import android.support.design.widget.Snackbar ; 149 import android.view.View ; 150 import android.support.design.widget.NavigationView ; 151 import android.support.v4.view.GravityCompat ; 152 import android.support.v4.widget.DrawerLayout ; 153 import android.support.v7.app.ActionBarDrawerToggle ; 154 import android.support.v7.app.AppCompatActivity ; 155 import android.support.v7.widget.Toolbar ; 156 import android.view.Menu ; 157 import android.view.MenuItem ; 158 import android.widget.Button ; 159 import android.widget.EditText ; 160 import android.widget.LinearLayout ; 161 import android.widget.Toast ; 162 import com.example.revan.hashtable_playstore.HashTableHitung.HashTable List ; 163 import com.example.revan.hashtable_playstore.HashTableHitung.HashTable Main ; 164 public class MainActivity extends AppCompatActivity 165
implements NavigationView.OnNavigationItemSelectedListener {
private EditText ETSearch ;
169
private EditText ETDelete ;
168
private EditText value_HashInput ;
167
private EditText textValue ;
166
170
174
setSupportActionBar(toolbar) ;
209
h a s h B u t t o n = ( B u t t o n ) findViewById(R.id. hash_InputButton ) ;
208
saveButton = (Button) findViewById(R.id. button_save ) ;
207
v a l u e _ H a s h I n p u t = ( E d i t T e x t ) findViewById(R.id. hash_value ) ;
206
textValue = (EditText) findViewById(R.id. value ) ;
205
204
210
Toolbar toolbar = (Toolbar) findViewById(R.id. toolbar ) ;
203
setContentView(R.layout. activity_main ) ;
202
super .onCreate(savedInstanceState) ;
201
protected void onCreate (Bundle savedInstanceState) {
200
@Override
tampil = (Button) findViewById(R.id. tampil ) ;
ETDelete = (EditText) findViewById(R.id. ET_Delete ) ;
B i t m a p b g = B i t m a p .createBitmap( 720 , 1280 , Bitmap.Config. ARGB_8888 ) ;
sharedPreferences = getSharedPreferences( MyPREFERENCES , Context. MODE_PRIVATE ) ;
221
public void onClick (View view) {
220
@Override
219
@RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
218
saveButton .setOnClickListener( new View.OnClickListener() {
217
216
211
II = (LinearLayout) findViewById(R.id. linear ) ;
215
Reset = (Button) findViewById(R.id. BT_Reset ) ;
214
SearchButton = (Button) findViewById(R.id. BT_Search ) ;
213
DeleteButton = (Button) findViewById(R.id. BT_Delete ) ;
212
ETSearch = (EditText) findViewById(R.id. ET_Search ) ;
199
198
private Button SearchButton ;
181
public static final String Value = "valueKey" ;
185
public int panjangy_overlaySearch = 140 ;
184
public int vary_overlaySearch = 50 ;
183
public int panjangx_overlaySearch = 140 ;
182
public int varx_overlaySearch = 50 ;
public int panjangy_ExtendsSearch = 140 ;
public static final String MyPREFERENCES = "MyPrefs" ;
180
public int vary_ExtendsSearch = 50 ;
179
public int panjangx_ExtendsSearch = 140 ;
177 178
public int height = 10 ;
176
private Button Reset ;
175
186
187
II ;
193
LinearLayout
197
SharedPreferences sharedPreferences ;
196
HashTableMain ht ;
195
Paint panah = new Paint() ;
194
Paint TextArray = new Paint() ;
Paint strokePaint = new Paint() ;
Canvas canvas ;
192
Paint fillPaint = new Paint() ;
191
Paint strokeSearch = new Paint() ;
190
Paint extendShape = new Paint() ;
189
Paint overlay = new Paint() ;
188
fillPaint .setStyle(Paint.Style. FILL ) ;
222
250
Toast.makeText(MainActivity. this, "Finish" , Toast. LENGTH_LONG ) ;
253
II .setBackground( new BitmapDrawable( bg )) ;
252
setHt( ht ) ;
251
ht = new HashTableMain(x) ;
}
}
249
ArrayTextY = ArrayTextY + 100 ;
248
panjangy = panjangy + 100 ;
247
vary = 10 + panjangy ;
246
canvas.drawText(String.valueOf( "[" +Array+ " ]" ) , ArrayTextX , ArrayTextY , TextArray ) ;
254
255
canvas.drawRect(varx , vary , panjangx , panjangy , strokePaint ) ;
i n t input_hash = Integer.valueOf( value_HashInput .getText().toString()).intValue() ;
264
getHt().insertvalue(input_hash) ;
263
int hashHitung = input_hash%x ;
262
i n t x = Integer.valueOf( textValue .getText().toString()).intValue() ;
261
260
}) ;
public void onClick (View v) {
259
@Override
258
@RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
257
hashButton .setOnClickListener( new View.OnClickListener() {
256
245
244
fillPaint .setColor(Color.parseColor( "#DA70D6" ) ) ;
f i n a l String strValue = textValue .getText().toString() ;
232
i n t x = Integer.valueOf( textValue .getText().toString()).intValue() ;
231
editor.putString( Value , strValue) ;
230
SharedPreferences.Editor editor = sharedPreferences .edit() ;
229
228
233
TextArray .setTextSize( 30 ) ;
227
TextArray .setColor(Color. BLACK ) ;
226
strokePaint .setStrokeWidth( 5 ) ;
224 225
strokePaint .setStyle(Paint.Style. STROKE ) ;
223
final int varx = 50 ;
int vary = 50 ;
canvas.drawRect(varx , vary , panjangx , panjangy , fillPaint ) ;
239
243
int Array = +y ;
242
for ( int y = ; y < x ; y++) { // DRAW CANVAS ARRAY AWAL
241
setStrokePaint( strokePaint ) ;
240
setCanvas(canvas) ;
final Canvas canvas = new Canvas( bg ) ;
234
238
int ArrayTextX = 10 ;
237
int ArrayTextY = 100 ;
236
int panjangy = 140 ;
235
int panjangx = 140 ;
redrawCanvas() ;
Toast.makeText(MainActivity. this, input_hash +
265
" MODULO " + x + " = " + hashHitung , Toast. LENGTH_LONG ).show() ; }
266 267
DeleteButton .setOnClickListener( new
268
View.OnClickListener() { @RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
269
@Override
270
public void onClick (View view) {
271
i n t remove_Hash =
272
Integer.valueOf( ETDelete .getText().toString()).intValue() ; getHt().removevalue(remove_Hash) ;
273
redrawCanvas() ;
274
}
275
}) ;
276
SearchButton .setOnClickListener( new
277
View.OnClickListener() {
278
@RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
279
@Override
280
public void onClick (View view){
281
redrawCanvas() ;
282
strokeSearch .setStyle(Paint.Style. STROKE ) ;
283
strokeSearch .setColor(Color. RED ) ;
284
strokeSearch .setStrokeWidth( 5 ) ;
285
i n t search_Hash =
286
Integer.valueOf( ETSearch .getText().toString()).intValue() ; getHt().getLoc2(search_Hash) ;
287
int LocY = getHt().getLoc2(search_Hash)[ ] ;
288
final int LocX = getHt().getLoc2(search_Hash)
289
[ 1 ] ; redrawCanvas() ;
290
if (LocX == 100 && LocY== 100 ) {
291
Toast.makeText(MainActivity. this,
292
search_Hash + " TIDAK DITEMUKAN " , Toast. LENGTH_LONG ).show() ; } else {
293
//Toast.makeText(MainActivity.this,
294
search_Hash + " DITEMUKAN " + " DI ARRAY " + LocY + " LIST " + LocX, Toast.LENGTH_LONG).show(); }
295
if (LocX == 1000 && LocY== 1000 ) {
296
Toast.makeText(MainActivity. this,
297
search_Hash + " TIDAK DITEMUKAN " , Toast. LENGTH_LONG ).show() ; } else {
298
//Toast.makeText(MainActivity.this,
299
search_Hash + " DITEMUKAN " + " DI ARRAY " + LocY + " LIST " + LocX, Toast.LENGTH_LONG).show(); }
300
varx_overlaySearch =
50 ;301
panjangx_overlaySearch = 140 ;
302
vary_overlaySearch =
50 ;303
panjangy_overlaySearch = 140 ;
304
for ( int y_overlay = ; y_overlay < LocY ;
305
y_overlay++) {
- + vary_overlaySearch = 1 0
306
panjangy_overlaySearch ; panjangy_overlaySearch =
307
}
308
varx_ExtendsSearch =
50 ;309
panjangx_ExtendsSearch = 140 ;
310
vary_ExtendsSearch =
50 ;311
panjangy_ExtendsSearch = 140 ;
312
for ( int y_overlay = ; y_overlay < LocY ;
313
y_overlay++) {
- + vary_ExtendsSearch = 1 0
314
panjangy_ExtendsSearch ; panjangy_ExtendsSearch =
315
- + panjangy_ExtendsSearch 100 ; }
316
int count = 2037 ;
317
height = ;
318
CountDownTimer timer = new
319
CountDownTimer(count , 90 ) {
@Override
320
public void onTick ( long
321
millisUntilFinished) { height = height * +(
7 LocX ) ;
322
redrawCanvas() ;
323
if ( LocX >= ) {
324
50 height , va + getCanvas().drawRect(
325
- + ry_ExtendsSearch , 140 height , panjangy_ExtendsSearch , strokeSearch ) ;
}
326
else if ( LocX == ) {
327
getCanvas().drawRect( height , 30 ,
328
- + 100 height , 100 , strokeSearch ) ;
}
329
II .setBackground( new
330
BitmapDrawable( bg )) ; }
331
@Override
332
public void onFinish () {
333
}
334
} ;
335
timer.start() ;
336
if ( L o c X = = )
337
50 , + height vary_ExtendsSearch , 140 height , + getCanvas().drawRect( panjangy_ExtendsSearch , strokeSearch ) ; }
338
}) ;
339
Reset .setOnClickListener( new View.OnClickListener() {
340
@RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
341
@Override
342
public void onClick (View view) {
343
getHt().makeEmpty() ;
344
Paint fillPaint = new Paint() ;
345
final Paint strokePaint = new Paint() ;
346
fillPaint.setStyle(Paint.Style. FILL ) ;
347
fillPaint.setColor(Color.parseColor( "#da4897" )
348
) ; Bitmap bg = Bitmap.createBitmap( 720 , 1280 ,
349
int reset = ;
350
ht = new HashTableMain(reset) ;
351
setHt( ht ) ;
352
redrawCanvas() ;
353
int x = ;
354
final int varx = 10 ;
355
int vary = 10 ;
356
int panjangx = 100 ;
357
int panjangy = 100 ;
358
final Canvas canvas = new Canvas(bg) ;
359
setCanvas(canvas) ;
360
setStrokePaint(strokePaint) ;
361
for ( int y = ; y < x ; y++) { // DRAW CANVAS
362
ARRAY AWAL canvas.drawRect(varx , vary , panjangx ,
363
panjangy , fillPaint) ; canvas.drawRect(varx , vary , panjangx ,
364
panjangy , strokePaint) ; vary = 10 + panjangy ;
365
panjangy = panjangy + 100 ;
366
}
367
LinearLayout II = (LinearLayout)
368
findViewById(R.id. linear ) ;
II.setBackground( new BitmapDrawable(bg)) ;
369
}
370
}) ;
371
tampil .setOnClickListener( new View.OnClickListener() {
372
@RequiresApi ( api = Build.VERSION_CODES. JELLY_BEAN )
373
@Override
374
public void onClick (View view) {
375
getHt().printHashTable() ;
376
redrawCanvas() ;
377
Toast.makeText(MainActivity. this,
378
" \n " + " NOTICE 1 : SET ARRAY FIRST"
379
- + " NOTICE 2 : DONT INPUT SAME
380
VALUE" , Toast. LENGTH_LONG ).show() ; }
381
}) ;
382
DrawerLayout drawer = (DrawerLayout)
383
findViewById(R.id. drawer_layout ) ; ActionBarDrawerToggle toggle = new
384
ActionBarDrawerToggle( t h i s , drawer , toolbar ,
385
R.string. navigation_drawer_open , R.string. navigation_drawer_close ) ;
drawer.setDrawerListener(toggle) ;386
toggle.syncState() ;
387
NavigationView navigationView = (NavigationView)
388
findViewById(R.id. nav_view ) ; navigationView.setNavigationItemSelectedListener( this ) ;
389
}
390
@Override
391
public void onBackPressed () {
392
DrawerLayout drawer = (DrawerLayout)
393
if (drawer.isDrawerOpen(GravityCompat. START )) {
394
drawer.closeDrawer(GravityCompat. START ) ;
395
} else {
396
super .onBackPressed() ;
397
}
398
}
399
@Override
400
public boolean onCreateOptionsMenu (Menu menu) {
401
getMenuInflater().inflate(R.menu. main , menu) ;
402
return true;
403
}
404
@Override
405
public boolean onOptionsItemSelected (MenuItem item) {
406
int id = item.getItemId() ;
407
//noinspection SimplifiableIfStatement
408
if (id == R.id. action_settings ) {
409
return true;
410
}
411
return super .onOptionsItemSelected(item) ;
412
}
413
@SuppressWarnings ( "StatementWithEmptyBody" )
414
@Override
415
public boolean onNavigationItemSelected (MenuItem item) {
416
//Memeriksa untuk melihat item yang akan dilklik dan
417
melalukan aksi switch (item.getItemId()) {
418
// pilihan menu item navigasi akan menampilkan
419
pesan toast klik kalian bisa menggantinya //dengan intent activity
420
case R.id. nav_camera :
421
I n t e n t a b o u t = new
422
Intent(getApplicationContext() , AboutActivity. class ) ;
startActivity(about) ;
423
return true;
424
case R.id. nav_gallery :
425
I n t e n t i n f o = new
426
Intent(getApplicationContext() , UserGuideActivity. class ) ;
startActivity(info) ;
427
return true;
428
case R.id. nav_share :
429
Toast.makeText(getApplicationContext() , "Share
430
Telah Dipilih" , Toast. LENGTH_SHORT ).show() ; return true;
431
case R.id. nav_send :
432
Toast.makeText(getApplicationContext() , "Send
433
Telah Dipilih" , Toast. LENGTH_SHORT ).show() ; return true;
434
}
435
return false;
436
}
437
438
470
for ( int i = ; i < getHt().getTABLE_SIZE() ; i++) {
474
HashTableList[] entry = getHt().getTable() ;
473
else {
472
}
471
Toast.makeText( t h i s , "null data" , Toast. LENGTH_SHORT ).show() ;
if (getHt().getTable() == null ){
HashTableList tempArray = entry[i] ;
469
II .setBackground( new BitmapDrawable( bg )) ;
468
getCanvas().drawColor( , PorterDuff.Mode. CLEAR ) ;
467
int ArrayTextX =
10 ;
466
int ArrayTextY = 100 ;
465
475
476
464
panah .setStyle(Paint.Style. FILL ) ;
487
TextArray .setTextSize( 30 ) ;
486
TextArray .setColor(Color. BLACK ) ;
485
panah .setStrokeWidth(
6 ) ;484
panah .setColor(Color. GRAY ) ;
483
482
int Array = +i ;
strokePaint .setStrokeWidth( 5 ) ;
481
strokePaint .setColor(Color. GRAY ) ;
480
strokePaint .setStyle(Paint.Style. STROKE ) ;
479
fillPaint .setColor(Color.parseColor( "#DA70D6" ) ) ;
478
fillPaint .setStyle(Paint.Style. FILL ) ;
477
int panahlurus2Y = 110 ;
int panahlurus2X = 180 ;
public void redrawCanvas (){
int vary_overlay ;
450
int panahstartX = 140 ; //100
449
int hashinput_toTableX ;
448
int hashinput_toTableY ;
447
int panjangy_overlay ;
446
445
451
int panjangx_overlay ;
444
int varx_overlay ;
443
int panjangy = 140 ;
441 442
int vary = 50 ;
440
final int varx =
50 ;
439
int panahstartY = 90 ; //50
int panahstopX = 180 ; //135
463
458
int panahlurusY =
70 ;
462
int panahlurusX = 180 ;
461
int panahbawahXY = 180 ;
460
int panahbawahYX = 195 ;
459
int panahbawahY =
90 ;
int panahbawahX = 110 ;
452
457
int panahatasXY = 180 ;
456
int panahatasYX = 195 ;
455
int panahatasY =
90 ;
454
int panahatasX =
70 ;
453
int panahstopY = 90 ; //50
getCanvas().drawRect(varx , vary , panjangx , panjangy , fillPaint ) ;
488
if (hashinput_toTableX > ) {
final String HashValue = String.valueOf(tempArray. value ) ;
507
hashinput_toTableY = getHt().getLoc(tempArray. value )[ ] ;
508
hashinput_toTableX = getHt().getLoc(tempArray. value )[
1 ] ;
509
for ( int y_overlay = ; y_overlay < hashinput_toTableY ; y_overlay++) {
510
vary_overlay = 1 0 + panjangy_overlay ;
511
panjangy_overlay = panjangy_overlay + 100 ;
512
}
513
514
panjangy_overlay = 140 ;
int shifting = hashinput_toTableX * 150 ;
515
i n t shiftingX = (hashinput_toTableX- 1 ) * 150 ;
516
i n t shiftingText = hashinput_toTableX * 150 ;
517
i n t shiftingY = hashinput_toTableY * 100 ;
518
getCanvas().drawLine(panahstartX+ shiftingX , panahstartY + shiftingY , panahstopX+shiftingX , panahstopY+ shiftingY , panah ) ;
519
getCanvas().drawLine(panahatasXY+ shiftingX , p a n a h a t a s X + s h i f t i n g Y , panahatasYX+shiftingX , panahatasY+ shiftingY , panah ) ;
520
getCanvas().drawLine(panahbawahXY +shiftingX , panahbawahX+ shiftingY , panahbawahYX+shiftingX , panahbawahY+ shiftingY , panah ) ;
521
506
505
getCanvas().drawRect(varx , vary , panjangx , panjangy , strokePaint ) ;
496
489
getCanvas().drawText(String.valueOf( "[" +Array+ "
490
ArrayTextY = ArrayTextY + 100 ;
491
vary = 10 + panjangy ;
492
panjangy = panjangy + 100 ;
493
overlay .setStyle(Paint.Style. FILL ) ;
494
overlay .setColor(Color.parseColor( "#FFEFD5" )) ;
495
extendShape .setStyle(Paint.Style. FILL ) ;
extendShape .setColor(Color.parseColor( "#DA70D6 " )) ;
vary_overlay = 50 ;
501
504
panjangx_overlay = 140 ;
503
varx_overlay = 50 ;
502
while (tempArray != null ) {
if (entry[i] != null ) {
497
500
Text.setTextSize( 30 ) ;
499
Text.setColor(Color.parseColor( "#DA70D6" )) ;
498
Paint Text = new Paint() ;
getCanvas().drawLine(panahlurusX+ shiftingX , panahlurusY+ shiftingY , panahlurus2X+shiftingX , panahlurus2Y+ shiftingY , panah ) ;
getCanvas().drawRect(varx_overlay
522
+ s h i f t i n g , vary_overlay , p a n j a n g x _ o v e r l a y + s h i f t i n g ,