-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTERNAL: Add sampling method to random get in set #825
Conversation
@ing-eoking @namsic ๋ง์ฝ, ๋ฆ์ด์ง๋ค๋ฉด, if (count >= info->ccnt || count == 0) { /* Return all */
fcnt = do_set_elem_traverse_dfs(info, info->root, count, delete, elem_array);
} else { /* Return some */
fcnt = do_set_elem_traverse_rand(info, count, delete, elem_array);
} |
6216aa1
to
d85e176
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
engines/default/coll_set.c
Outdated
} else if (node->hcnt[hidx] > 0) { | ||
set_elem_item *elem = node->htab[hidx]; | ||
while (elem != NULL) { | ||
if (rand() % *remain < count - fcnt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ง๋ฌธ์ด ์์ต๋๋ค.
ํ๋ฅ ์ ์ผ๋ก ์ ํํ๊ฒ ๋๋ ๋ฐ, ์ต์ข
์ ์ผ๋ก count ๊ฐ๋ฅผ ์ ํํ๋ค๋ ๊ฒ์ด ๋ณด์ฅ๋๋์?
์ฐธ๊ณ ์ฌํญ์ผ๋ก, ์๋์ ๊ฐ์ด ๊ดํธ๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋์ ๊ฒ ๊ฐ์ต๋๋ค.
((rand() % *remain) < (count - fcnt))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๋ฅ ์ ์ผ๋ก ์ ํํ๊ฒ ๋๋ ๋ฐ, ์ต์ข ์ ์ผ๋ก count ๊ฐ๋ฅผ ์ ํํ๋ค๋ ๊ฒ์ด ๋ณด์ฅ๋๋์?
elem์ ์ง๋๊ฐ ๋๋ง๋ค remain ๊ฐ์ ๋ฌด์กฐ๊ฑด 1์ฉ ๊ฐ์ํ๋ฉฐ, ๊ฒฐ๊ตญ remain ๊ฐ์ด ๋จ์ ๋ฝ์์ผ ํ ๊ฐ์(count-fcnt)์ ๊ฐ๊น์์ง๊ฒ ๋ฉ๋๋ค.
remain ๊ฐ์ด count - fcnt ๊ณผ ๊ฐ์์ง๋ฉด, rand() % remain ์ ๊ฒฐ๊ณผ๊ฐ ํญ์ remain๋ณด๋ค ์์ ๊ฐ์ ๊ฐ๊ฒ ๋์ด elem์ด count ๊ฐ์๋งํผ ๋ ๋๊น์ง 100% ํ๋ฅ ๋ก elem์ด ๋ฝํ๊ฒ ๋ฉ๋๋ค.
๊ทธ๋์ remain์ด 0์ ๊ฐ๊น์์ง์๋ก ํ๋ฅ ๊ฐ์ด 100%๊น์ง ์ฆ๊ฐํ๊ธฐ ๋๋ฌธ์ count ๋งํผ ๋ฝํ๋ ๊ฒ์ด ๋ณด์ฅ๋ฉ๋๋ค.
d85e176
to
298d345
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌ๋ทฐ ์๋ฃ
if ((rand() % *remain) < (count - fcnt)) { | ||
elem->refcount++; | ||
elem_array[fcnt] = elem; | ||
fcnt++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด ์์น์ ์๋ ์กฐ๊ฑด๋ง ์์ผ๋ฉด ๋ฉ๋๋ค.
if (fcnt >= count) break;
engines/default/coll_set.c
Outdated
} | ||
*remain -= 1; | ||
elem = elem->next; | ||
if (fcnt >= count || *remain == 0) break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*remain == 0
์กฐ๊ฑด์ ์์ด๋ ๋ฉ๋๋ค.
engines/default/coll_set.c
Outdated
if (fcnt >= count || *remain == 0) break; | ||
} | ||
} | ||
if (fcnt >= count || *remain == 0) break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ๊ธฐ๋ fcnt์ ๋ํ ์กฐ๊ฑด๋ง ์์ผ๋ฉด ๋ฉ๋๋ค.
@@ -532,6 +532,36 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node, | |||
return fcnt; | |||
} | |||
|
|||
static int do_set_elem_traverse_sampling(set_meta_info *info, set_hash_node *node, | |||
const uint32_t count, uint32_t *remain, | |||
set_elem_item **elem_array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remain๊ณผ count ์ธ์์ ์์๋ฅผ ๋ณ๊ฒฝํ๊ณ ,
remain์ ํฌ์ธํฐ ํ์
์ด ์๋ uint32_t ํ์
์ผ๋ก ํ๋ฉด ์ข๊ฒ ์ต๋๋ค.
๋์ , ํ์ ๋
ธ๋์ ๋ํ traverse๊ฐ ๋๋๋ฉด, remain์ ํ์ ๋
ธ๋์ ์๋ element ๊ฐ์๋งํผ ๊ฐ์ํ๋ฉด ๋ฉ๋๋ค.
engines/default/coll_set.c
Outdated
} else { /* Use sampling */ | ||
uint32_t remain = info->ccnt; | ||
fcnt = do_set_elem_traverse_sampling(info, info->root, | ||
count, &remain, elem_array); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remain ํ์ ์ ๋ณ๊ฒฝํ๋ฉด, ์๋์ ๊ฐ์ด ํธ์ถํ๋ฉด ๋ฉ๋๋ค.
fcnt = do_set_elem_traverse_sampling(info, info->root, info->ccnt,
count, elem_array);
298d345
to
7ebc7e6
Compare
๐ Related Issue
โจ๏ธ What I did
do_set_elem_traverse_sampling()
(๋จ์ ํ์ ์์ ๊ฐ์) / (๋จ์ ํ์ ์์ ๊ฐ์)
์ ํ ํ๋ฅ ์์