summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/random-weight.h
diff options
context:
space:
mode:
authorgammafunk <gammafunk@gmail.com>2014-03-22 22:38:18 -0500
committergammafunk <gammafunk@gmail.com>2014-03-22 23:05:00 -0500
commitafc2efcec23fa2265b3336c818827fa886c4e6fb (patch)
tree2d215e9fc43cd9dfb275f5cdcd621760e478f3af /crawl-ref/source/random-weight.h
parentd3e69da935d934fc79cdb77afc2a3dd222b0ce04 (diff)
downloadcrawl-ref-afc2efcec23fa2265b3336c818827fa886c4e6fb.tar.gz
crawl-ref-afc2efcec23fa2265b3336c818827fa886c4e6fb.zip
Document some functions and remove some des whitespace
Diffstat (limited to 'crawl-ref/source/random-weight.h')
-rw-r--r--crawl-ref/source/random-weight.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/crawl-ref/source/random-weight.h b/crawl-ref/source/random-weight.h
index 9beca03c5e..eea19e7b56 100644
--- a/crawl-ref/source/random-weight.h
+++ b/crawl-ref/source/random-weight.h
@@ -2,10 +2,13 @@
#define RANDOM_WEIGHT_H
/*
- * Weighted choice.
+ * Get a random weighted choice.
*
* Weights are assumed to be non-negative, but are allowed to be zero.
- * Returns NULL if nothing found, i.e., if all weights are zero.
+ * @param choices The vector of choice-weight pairs to choose from.
+ *
+ * @returns A pointer to the item in the chosen pair, or NULL if all
+ * weights are zero.
*/
template <typename T>
T* random_choose_weighted(vector<pair<T, int> >& choices)
@@ -25,8 +28,14 @@ T* random_choose_weighted(vector<pair<T, int> >& choices)
}
/*
- * Same as above, but weights are in a FixedVector. Entries with a weight <= 0
- * are skipped. Returns the index of the chosen entry, or -1 if nothing found.
+ * Get an index for a random weighted choice using a fixed vector of
+ * weights.
+ *
+ * Entries with a weight <= 0 are skipped.
+ * @param choices The fixed vector with weights for each item.
+ *
+ * @returns A index corresponding to the selected item, or -1 if all
+ * weights were skipped.
*/
template <typename T, int SIZE>
int random_choose_weighted(FixedVector<T, SIZE>& choices)