Skip to content
Snippets Groups Projects
Verified Commit 0edcd0ad authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

lib/generic/lru: doc nitpicks

parent 40ad0c16
No related branches found
No related tags found
1 merge request!675daemon: attempt of refactoring
......@@ -21,7 +21,15 @@ typedef struct lru_group lru_group_t;
struct lru_item {
uint16_t key_len, val_len; /**< Two bytes should be enough for our purposes. */
char data[]; /**< Place for both key and value. */
char data[];
/**< Place for both key and value.
*
* We use "char" to satisfy the C99+ aliasing rules.
* See C99 section 6.5 Expressions, paragraph 7.
* Any type can be accessed through char-pointer,
* so we can use a common struct definition
* for all types being held.
*/
};
/** @internal Compute offset of value in struct lru_item. */
......
......@@ -24,32 +24,31 @@
* most frequent keys/hashes. This tracking is done for *more* keys than
* those that are actually stored.
*
* # Example usage:
*
* Example usage:
* @code{.c}
* // Define new LRU type
* typedef lru_t(int) lru_int_t;
*
* // Create LRU
* lru_int_t *lru;
* lru_create(&lru, 5, NULL);
* lru_create(&lru, 5, NULL, NULL);
*
* // Insert some values
* int *pi = lru_get_new(lru, "luke", strlen("luke"));
* int *pi = lru_get_new(lru, "luke", strlen("luke"), NULL);
* if (pi)
* *pi = 42;
* pi = lru_get_new(lru, "leia", strlen("leia"));
* pi = lru_get_new(lru, "leia", strlen("leia"), NULL);
* if (pi)
* *pi = 24;
*
* // Retrieve values
* int *ret = lru_get_try(lru, "luke", strlen("luke"));
* int *ret = lru_get_try(lru, "luke", strlen("luke"), NULL);
* if (!ret) printf("luke dropped out!\n");
* else printf("luke's number is %d\n", *ret);
*
* char *enemies[] = {"goro", "raiden", "subzero", "scorpion"};
* for (int i = 0; i < 4; ++i) {
* int *val = lru_get_new(lru, enemies[i], strlen(enemies[i]));
* int *val = lru_get_new(lru, enemies[i], strlen(enemies[i]), NULL);
* if (val)
* *val = i;
* }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment