From: Deskull Date: Sun, 13 Jan 2019 04:56:40 +0000 (+0900) Subject: [Refactor] #37353 ソート処理をsort.c/hに分離。 / Separate to sort.c/h. X-Git-Url: http://git.osdn.net/view?p=hengband%2Fhengband.git;a=commitdiff_plain;h=f3f34986b26c373491579443ce163995330a9b76 [Refactor] #37353 ソート処理をsort.c/hに分離。 / Separate to sort.c/h. --- diff --git a/Hengband_vcs2017/Hengband/Hengband.vcxproj b/Hengband_vcs2017/Hengband/Hengband.vcxproj index 88aec26ad..fd0a64d55 100644 --- a/Hengband_vcs2017/Hengband/Hengband.vcxproj +++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj @@ -233,6 +233,7 @@ + @@ -309,6 +310,7 @@ + diff --git a/src/Makefile.am b/src/Makefile.am index fbfe7cdef..c71652b19 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ hengband_SOURCES = \ rooms-special.c rooms-special.h rooms-trap.c rooms-trap.h rooms-vault.c \ rooms-vault.h save.c scores.c selfinfo.c selfinfo.h shoot.c snipe.c \ spells1.c spells2.c spells3.c spells-summon.c spells-summon.h \ + sort.c sort.h \ store.h store.c tables.c trap.c trap.h types.h util.c \ variable.c wild.c wizard1.c wizard2.c \ world.c world.h xtra1.c xtra2.c z-config.h \ diff --git a/src/bldg.c b/src/bldg.c index c4447af03..fd3bd6a21 100644 --- a/src/bldg.c +++ b/src/bldg.c @@ -17,6 +17,7 @@ #include "monsterrace-hook.h" #include "melee.h" #include "world.h" +#include "sort.h" /*! * ループ中で / hack as in leave_store in store.c diff --git a/src/cmd-activate.c b/src/cmd-activate.c index 8900d3331..d84745845 100644 --- a/src/cmd-activate.c +++ b/src/cmd-activate.c @@ -10,6 +10,7 @@ #include "cmd-activate.h" #include "object-hook.h" #include "spells-summon.h" +#include "sort.h" /*! * @brief ペット入りモンスターボールをソートするための比較関数 diff --git a/src/cmd-item.c b/src/cmd-item.c index d83ef9d0a..1b1f0ac05 100644 --- a/src/cmd-item.c +++ b/src/cmd-item.c @@ -22,6 +22,7 @@ #include "cmd-zapwand.h" #include "object-hook.h" +#include "sort.h" /*! diff --git a/src/cmd-pet.c b/src/cmd-pet.c index 2d0bd7c70..632926a1e 100644 --- a/src/cmd-pet.c +++ b/src/cmd-pet.c @@ -1,5 +1,6 @@ #include "angband.h" #include "melee.h" +#include "sort.h" /*! * @brief プレイヤーの騎乗/下馬処理判定 diff --git a/src/cmd4.c b/src/cmd4.c index 67d28bd5d..d99441f9e 100644 --- a/src/cmd4.c +++ b/src/cmd4.c @@ -43,6 +43,7 @@ #include "cmd-pet.h" #include "world.h" #include "player-status.h" +#include "sort.h" /* diff --git a/src/externs.h b/src/externs.h index 9d41563c2..6b396e758 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1269,8 +1269,6 @@ extern void redraw_window(void); extern bool change_panel(POSITION dy, POSITION dx); extern void verify_panel(void); extern cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode); -extern void ang_sort_aux(vptr u, vptr v, int p, int q); -extern void ang_sort(vptr u, vptr v, int n); extern bool target_able(MONSTER_IDX m_idx); extern bool target_okay(void); extern bool target_set(BIT_FLAGS mode); diff --git a/src/files.c b/src/files.c index 21375de34..26c66a2e9 100644 --- a/src/files.c +++ b/src/files.c @@ -16,6 +16,7 @@ #include "angband.h" #include "world.h" #include "player-status.h" +#include "sort.h" /* diff --git a/src/rooms-pitnest.c b/src/rooms-pitnest.c index 46fa8972b..4b61cc16b 100644 --- a/src/rooms-pitnest.c +++ b/src/rooms-pitnest.c @@ -4,6 +4,7 @@ #include "rooms.h" #include "rooms-pitnest.h" #include "monsterrace-hook.h" +#include "sort.h" diff --git a/src/save.c b/src/save.c index 67ef9fe23..1be5a3a91 100644 --- a/src/save.c +++ b/src/save.c @@ -12,6 +12,7 @@ */ #include "angband.h" +#include "sort.h" diff --git a/src/sort.c b/src/sort.c new file mode 100644 index 000000000..62c610284 --- /dev/null +++ b/src/sort.c @@ -0,0 +1,69 @@ +#include "angband.h" +#include "sort.h" + + +/* + * Angband sorting algorithm -- quick sort in place + * + * Note that the details of the data we are sorting is hidden, + * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" + * function hooks to interact with the data, which is given as + * two pointers, and which may have any user-defined form. + */ +void ang_sort_aux(vptr u, vptr v, int p, int q) +{ + int z, a, b; + + /* Done sort */ + if (p >= q) return; + + /* Pivot */ + z = p; + + /* Begin */ + a = p; + b = q; + + /* Partition */ + while (TRUE) + { + /* Slide i2 */ + while (!(*ang_sort_comp)(u, v, b, z)) b--; + + /* Slide i1 */ + while (!(*ang_sort_comp)(u, v, z, a)) a++; + + /* Done partition */ + if (a >= b) break; + + /* Swap */ + (*ang_sort_swap)(u, v, a, b); + + /* Advance */ + a++, b--; + } + + /* Recurse left side */ + ang_sort_aux(u, v, p, b); + + /* Recurse right side */ + ang_sort_aux(u, v, b + 1, q); +} + + +/* + * Angband sorting algorithm -- quick sort in place + * + * Note that the details of the data we are sorting is hidden, + * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" + * function hooks to interact with the data, which is given as + * two pointers, and which may have any user-defined form. + */ +void ang_sort(vptr u, vptr v, int n) +{ + /* Sort the array */ + ang_sort_aux(u, v, 0, n - 1); +} + + + diff --git a/src/sort.h b/src/sort.h new file mode 100644 index 000000000..813a5addd --- /dev/null +++ b/src/sort.h @@ -0,0 +1,3 @@ +extern void ang_sort_aux(vptr u, vptr v, int p, int q); +extern void ang_sort(vptr u, vptr v, int n); + diff --git a/src/wizard1.c b/src/wizard1.c index d58ad2f0a..198c8e92d 100644 --- a/src/wizard1.c +++ b/src/wizard1.c @@ -11,6 +11,7 @@ */ #include "angband.h" +#include "sort.h" #ifdef ALLOW_SPOILERS diff --git a/src/xtra2.c b/src/xtra2.c index 68f1de797..2b46503fb 100644 --- a/src/xtra2.c +++ b/src/xtra2.c @@ -16,6 +16,7 @@ #include "object-curse.h" #include "monsterrace-hook.h" #include "objectkind-hook.h" +#include "sort.h" #define REWARD_CHANCE 10 @@ -2089,71 +2090,6 @@ cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode) -/* - * Angband sorting algorithm -- quick sort in place - * - * Note that the details of the data we are sorting is hidden, - * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" - * function hooks to interact with the data, which is given as - * two pointers, and which may have any user-defined form. - */ -void ang_sort_aux(vptr u, vptr v, int p, int q) -{ - int z, a, b; - - /* Done sort */ - if (p >= q) return; - - /* Pivot */ - z = p; - - /* Begin */ - a = p; - b = q; - - /* Partition */ - while (TRUE) - { - /* Slide i2 */ - while (!(*ang_sort_comp)(u, v, b, z)) b--; - - /* Slide i1 */ - while (!(*ang_sort_comp)(u, v, z, a)) a++; - - /* Done partition */ - if (a >= b) break; - - /* Swap */ - (*ang_sort_swap)(u, v, a, b); - - /* Advance */ - a++, b--; - } - - /* Recurse left side */ - ang_sort_aux(u, v, p, b); - - /* Recurse right side */ - ang_sort_aux(u, v, b+1, q); -} - - -/* - * Angband sorting algorithm -- quick sort in place - * - * Note that the details of the data we are sorting is hidden, - * and we rely on the "ang_sort_comp()" and "ang_sort_swap()" - * function hooks to interact with the data, which is given as - * two pointers, and which may have any user-defined form. - */ -void ang_sort(vptr u, vptr v, int n) -{ - /* Sort the array */ - ang_sort_aux(u, v, 0, n-1); -} - - - /*** Targeting Code ***/