Skip to content

Commit 46a2d31

Browse files
committed
Copyedits
1 parent b4c303b commit 46a2d31

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

link-grammar/parse/count.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -933,42 +933,42 @@ static Count_bin do_count(int lineno, count_context_t *ctxt,
933933
/*
934934
* See do_parse() for the purpose of this function.
935935
*
936-
* The returned number of parses (called here "count") is a 32-bit
937-
* integer. However, this count may sometimes be very big - much more than
938-
* can be represented in 32-bits. In such a case it is just enough to know
939-
* that such an "overflow" occurred. Internally, big counts are clamped to
936+
* The returned number of parses (called "count" here) is a 32-bit
937+
* integer. However, this count may sometimes be very big - much larger than
938+
* can be represented in 32-bits. In such a case, it is just enough to know
939+
* that such an "overflow" occurred. Internally, large counts are clamped to
940940
* INT_MAX (2^31-1) - see parse_count_clamp() (we refer below to such
941941
* values as "clamped"). If the top-level do_count() (the one that is
942-
* called from do_parse()) returns this value, it means such an overflow
942+
* called from do_parse()) returns this value, it means that an overflow
943943
* has occurred.
944944
*
945945
* The function uses a 64-bit signed integer as a count accumulator - named
946946
* "total". The maximum value it can hold is 2^63-1. If it becomes greater
947-
* than INT_MAX, it is considered as a count overflow. A care should be
948-
* taken that this total itself would not overflow, else this detection
949-
* mechanism would be rendered useless. To that end, each value from which
950-
* this total is computed should be small enough so it would not overflow.
947+
* than INT_MAX, it is considered as a count overflow. Care must be
948+
* taken that this total itself does not overflow, else this detection
949+
* mechanism would malfunction. To that end, each value from which
950+
* this total is computed must be small enough so it does not overflow.
951951
*
952952
* The function has 4 code sections to calculate the count. Each of them,
953953
* when entered, returns a value which is clamped (or doesn't need to be
954954
* clamped). The are marked in the code with "Path 1a", "Path 1b",
955955
* "Path 2", and "Path 3".
956956
*
957957
* Path 1a, Path 1b: If there is a possible linkage between the given
958-
* words, return 1, else return 0. Here a count overflow cannot occur.
958+
* words, return 1, else return 0. Here, a count overflow cannot occur.
959959
*
960-
* Path 2: The total accumulate the result of the do_count() invocations
960+
* Path 2: The total accumulates the result of the do_count() invocations
961961
* that are done in a loop. The upper bound on the number of iterations is
962-
* twice (out loop) the maximum number of word disjuncts )inner loop).
962+
* twice (outer loop) the maximum number of word disjuncts (inner loop).
963963
* Assuming no more than 2^31 disjuncts per word, and considering that
964964
* each value is a result of do_count() which is clamped, the total is
965965
* less than (2*2^31)*(2^31`-1), which is less than 2^63-1, and hence just
966966
* needs to be clamped before returning.
967967
*
968968
* Path 3: The total is calculated as a sum of series of multiplications.
969969
* To prevent its overflow, we ensure that each term (including the total
970-
* itself) would not be greater than INT_MAX (2^31-1), so the result will
971-
* not be more than (2^31-1)+((2^31-1)*(2^31-1)) which is less than
970+
* itself) would not be greater than INT_MAX (2^31-1). Then the result will
971+
* not be more than (2^31-1)+((2^31-1)*(2^31-1)), which is less than
972972
* 2^63-1. In this path, each multiplication term that may be greater then
973973
* INT_MAX (leftcount and rightcount) is clamped before the
974974
* multiplication, and the total is clamped after the multiplication.
@@ -1419,11 +1419,12 @@ static Count_bin do_count(
14191419
* we know that the true total is zero. So we don't
14201420
* bother counting the other term at all, in that case. */
14211421

1422-
/* To enable 31-bit overflow detection, total, leftcount and
1423-
* rightcount are signed 64-bit, and are , a clamped cached
1424-
* value, or are clamped below before they are used. total is
1425-
* initially 0 and is clamped at the end of each iteration.
1426-
* So the result will not be more than (2^31-1)+((2^31-1)*(2^31-1))
1422+
/* To enable 31-bit overflow detection, `total`, `leftcount`
1423+
* and `rightcount` are signed 64-bit, and are clamped cached
1424+
* values, or are clamped below before they are used. `total`
1425+
* is initially 0 and is clamped at the end of each iteration.
1426+
* So the result will never be more than
1427+
* (2^31-1)+((2^31-1)*(2^31-1)),
14271428
* which is less than 2^63-1. */
14281429
if (leftpcount &&
14291430
(!lcnt_optimize || rightpcount || (0 != hist_total(&l_bnr))))

0 commit comments

Comments
 (0)