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. */
* 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;
* }