diff options
author | Raymond Hettinger <python@rcn.com> | 2004-10-01 15:14:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-10-01 15:14:39 (GMT) |
commit | 4ca4c7c8ccb681067d18fad063a3423fafc4d6f3 (patch) | |
tree | e30d63965b2f41b8d4df216de3c3983ff0b60f2a | |
parent | 61f05fb96d17e60272bea6557125d8dc10c48a3f (diff) | |
download | cpython-4ca4c7c8ccb681067d18fad063a3423fafc4d6f3.zip cpython-4ca4c7c8ccb681067d18fad063a3423fafc4d6f3.tar.gz cpython-4ca4c7c8ccb681067d18fad063a3423fafc4d6f3.tar.bz2 |
Clarify the relationship between indices.
-rw-r--r-- | Modules/collectionsmodule.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index 188b239..27236d9 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -7,7 +7,7 @@ All rights reserved. */ -#define BLOCKLEN 46 +#define BLOCKLEN 2 #define CENTER ((BLOCKLEN - 1) / 2) /* A `dequeobject` is composed of a doubly-linked list of `block` nodes. @@ -24,17 +24,19 @@ * * The indices, d.leftindex and d.rightindex are always in the range * 0 <= index < BLOCKLEN. + * Their exact relationship is: + * (d.leftindex + d.len - 1) % BLOCKLEN == d.rightindex. * * Empty deques have d.len == 0; d.leftblock==d.rightblock; * d.leftindex == CENTER+1; and d.rightindex == CENTER. * Checking for d.len == 0 is the intended way to see whether d is empty. * * Whenever d.leftblock == d.rightblock, - * d.leftindex + d.len == d.rightindex + 1. + * d.leftindex + d.len - 1 == d.rightindex. * - * However, when d.leftblock != rightblock, d.leftindex and d.rightindex - * are indices into distinct blocks and have no relationship to one - * another (for example, sometimes d.leftindex > d.rightindex). + * However, when d.leftblock != d.rightblock, d.leftindex and d.rightindex + * become indices into distinct blocks and either may be larger than the + * other. */ typedef struct BLOCK { |