www.gmindo.web.id/forum
Forum ini sudah tidak dipakai lagi. Silakan ke forum baru di www.gmindo.web.id/forum Very Happy

Terima kasih

Join the forum, it's quick and easy

www.gmindo.web.id/forum
Forum ini sudah tidak dipakai lagi. Silakan ke forum baru di www.gmindo.web.id/forum Very Happy

Terima kasih
www.gmindo.web.id/forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Intermediate] ds_map

Go down

[Intermediate] ds_map Empty [Intermediate] ds_map

Post by Kevin Blaze Coolerz Wed 23 Oct 2013, 12:39

ds_map adalah salah satu data struktur yg mungkin paling cocok untuk bikin inventory. Setiap data struktur punya perbedaan masing-masing, dan ds_map ini hampir mirip dengan ds_list, cuma bedanya ds_map punya nama key untuk tiap value nya (mirip Ini Files gitu)

Berikut perbedaan ds_map dan ds_list:

DS_LIST:
Code:
list=ds_list_create()
ds_list_add(list,100)
ds_list_add(list,200)
ds_list_add(list,300)
DS_MAP:
Code:
map=ds_map_create()
ds_map_add(map,"Item 1",100)
ds_map_add(map,"Item 2",200)
ds_map_add(map,"Item 3",300)
HASILNYA:
DS_LIST:
0 = 100
1 = 200
2 = 300

DS_MAP:
Item 1 = 100
Item 2 = 200
Item 3 = 300
Dalam ds_map, key nya sudah otomatis di sort, dan cara mencari nya pun sama dengan ds_list. Bedanya, ds_map tidak punya fungsi untuk mencari index (dalam ds_list, nama fungsinya yaitu ds_list_find_index() ). Tetapi, ds_map bisa mencari lebih canggih, berikut fungsi find pada ds_map:

ds_map_find_value(id, key)
jika kita kaitkan dengan Contoh Perbandingan diatas, maka ketika kita isi "Item 1" pada key di fungsi ini, maka akan return nilai 100. Contoh lainnya:

Code:
map_id=ds_map_create()
ds_map_add(map_id, "Permen", 100)
ds_map_add(map_id, "Kuaci", 20)
ds_map_add(map_id, "Ciki", 10)

/*contoh fungsi find:*/
banyak_ciki=ds_map_find_value(map_id,"Ciki")
Maka, nilai banyak_ciki=10.

Key tidak harus menggunakan string, pake angka/real juga bisa Very Happy

Selanjutnya,
ds_map_find_next(id,key)
Mencari nilai selanjutnya dari key yg kita input. Jika tadi kita input "Ciki", maka akan return "Kuaci". Karena key di sort secara ascending (A-Z), maka key diatas di susun menjadi "Ciki > Kuaci > Permen", setelah Ciki adalah Kuaci. Nilai akan return 0 jika key adalah key terakhir.

ds_map_find_previous(id,key)
Sama saja dengan yg diatas, cma bedanya ds_map akan return nilai key diatas key yang di tunjukan. Misal: jika kamu input "Permen", maka akan return "Kuaci" Very Happy

ds_map_find_first(id)
return key terkecil dalam map. Dalam hal ini yaitu "Ciki"

ds_map_find_last(id)
return key terbesar dalam map. Dalam hal ini yaitu "Permen"

Dan untuk fungsi yang lain, sebenarnya sama saja dengan fungsi data struktur yang lain. Ini sisa fungsi yg boleh kamu pelajari sendiri:

ds_map_create() Creates a new map. The function returns an integer as an id that must be used in all other functions to access the particular map.
ds_map_destroy(id) Destroys the map with the given id, freeing the memory used. Don't forget to call this function when you are ready with the structure.
ds_map_clear(id) Clears the map with the given id, removing all data from it but not destroying it.
ds_map_copy(id,source) Copies the map source into the map with the given id.
ds_map_size(id) Returns the number of key-value pairs stored in the map.
ds_map_empty(id) Returns whether the map is empty. This is the same as testing whether the size is 0.
ds_map_add(id,key,val) Adds the key-value pair to the map.
ds_map_replace(id,key,val) Replaces the value corresponding with the key with a new value.
ds_map_delete(id,key) Deletes the key and the corresponding value from the map. (If there are multiple entries with the same key, only one is removed.)
ds_map_exists(id,key) Returns whether the key exists in the map.
ds_map_write(id) Turns the data structure into a string and returns this string. The string can then be used to e.g. save it to a file. This provides an easy mechanism for saving data structures.
ds_map_read(id,str) Reads the data structure from the given string (as created by the previous call).

Jika masih kesulitan, coba pelajari ds_list :PGak susah kok, kalo ada niat pasti bisa Smile
Kevin Blaze Coolerz
Kevin Blaze Coolerz
Admin
Admin

100%
Jumlah posting : 3323
Points : 3795
Join date : 06.01.13
Age : 28
Lokasi : Palembang

http://kevin-blaze-coolerz.blogspot.com/

Kembali Ke Atas Go down

Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik