* The following wrapper functions are defined; each one is the same as
* the jmap.h generic equivalent except where noted:
*
+ * // Creating, errors and freeing.
* struct jmap_@name *jmap_@name_new(void);
* void jmap_@name_free(const struct jmap_@name *map);
* const char *jmap_@name_error(struct jmap_@name *map);
*
- * bool jmap_@name_add(const struct jmap_@name *map,
- * size_t index, const type *value);
+ * // Add, set, delete, test and get.
+ * bool jmap_@name_add(struct jmap_@name *map,
+ * unsigned long idx, const type *value);
* bool jmap_@name_set(const struct jmap_@name *map,
- * size_t index, const type *value);
- * bool jmap_@name_del(struct jmap_@name *map, size_t index);
- * bool jmap_@name_test(const struct jmap_@name *map, size_t index);
+ * unsigned long idx, const type *value);
+ * bool jmap_@name_del(struct jmap_@name *map, unsigned long idx);
+ * bool jmap_@name_test(const struct jmap_@name *map, unsigned long idx);
+ * type *jmap_@name_get(const struct jmap_@name *map, unsigned long idx);
*
- * type *jmap_@name_get(const struct jmap_@name *map, size_t index);
- * size_t jmap_@name_popcount(const struct jmap_@name *map,
- * size_t start, size_t end_incl);
- * size_t jmap_@name_nth(const struct jmap_@name *map,
- * size_t n, size_t invalid);
- * size_t jmap_@name_first(const struct jmap_@name *map,
- * size_t invalid);
- * size_t jmap_@name_next(const struct jmap_@name *map,
- * size_t prev, size_t invalid);
- * size_t jmap_@name_last(const struct jmap_@name *map,
- * size_t invalid);
- * size_t jmap_@name_prev(const struct jmap_@name *map,
- * size_t prev, size_t invalid);
+ * // Counting and iteration.
+ * unsigned long jmap_@name_popcount(const struct jmap_@name *map,
+ * unsigned long start,
+ * unsigned long end_incl);
+ * unsigned long jmap_@name_nth(const struct jmap_@name *map,
+ * unsigned long n, unsigned long invalid);
+ * unsigned long jmap_@name_first(const struct jmap_@name *map,
+ * unsigned long invalid);
+ * unsigned long jmap_@name_next(const struct jmap_@name *map,
+ * unsigned long prev,
+ * unsigned long invalid);
+ * unsigned long jmap_@name_last(const struct jmap_@name *map,
+ * unsigned long invalid);
+ * unsigned long jmap_@name_prev(const struct jmap_@name *map,
+ * unsigned long prev,
+ * unsigned long invalid);
*
- * type **jmap_@name_getval(const struct jmap_@name *map, size_t index);
+ * // Get pointers to values to use.
+ * type **jmap_@name_getval(const struct jmap_@name *map,
+ * unsigned long idx);
* void jmap_@name_putval(struct jmap_@name *map, type ***p);
* type **jmap_@name_nthval(struct jmap_@name *map,
- * size_t n, size_t *index);
+ * unsigned long n, unsigned long *idx);
* type **jmap_@name_firstval(const struct jmap_@name *map,
- * size_t *index);
- * type **jmap_@name_nextval(const struct jmap_@name *map, size_t *index);
- * type **jmap_@name_lastval(const struct jmap_@name *map, size_t *index);
- * type **jmap_@name_prevval(const struct jmap_@name *map, size_t *index);
+ * unsigned long *idx);
+ * type **jmap_@name_nextval(const struct jmap_@name *map,
+ * unsigned long *idx);
+ * type **jmap_@name_lastval(const struct jmap_@name *map,
+ * unsigned long *idx);
+ * type **jmap_@name_prevval(const struct jmap_@name *map,
+ * unsigned long *idx);
*/
#define JMAP_DEFINE_UINTIDX_TYPE(type, name) \
struct jmap_##name; \
return jmap_error((struct jmap *)map); \
} \
static inline bool jmap_##name##_add(struct jmap_##name *map, \
- size_t index, const type *value) \
+ unsigned long idx, const type *value) \
{ \
- return jmap_add((struct jmap *)map, index, (size_t)value); \
+ return jmap_add((struct jmap *)map, idx, (unsigned long)value); \
} \
static inline bool jmap_##name##_set(const struct jmap_##name *map, \
- size_t index, const type *value) \
+ unsigned long idx, const type *value) \
{ \
- return jmap_set((const struct jmap *)map, index, (size_t)value); \
+ return jmap_set((const struct jmap *)map, idx, (unsigned long)value); \
} \
-static inline bool jmap_##name##_del(struct jmap_##name *map, size_t index) \
+static inline bool jmap_##name##_del(struct jmap_##name *map, \
+ unsigned long idx) \
{ \
- return jmap_del((struct jmap *)map, index); \
+ return jmap_del((struct jmap *)map, idx); \
} \
-static inline bool jmap_##name##_test(const struct jmap_##name *map, \
- size_t index) \
+static inline bool jmap_##name##_test(const struct jmap_##name *map, \
+ unsigned long idx) \
{ \
- return jmap_test((const struct jmap *)map, (size_t)index); \
+ return jmap_test((const struct jmap *)map, (unsigned long)idx); \
} \
static inline type *jmap_##name##_get(const struct jmap_##name *map, \
- size_t index) \
+ unsigned long idx) \
{ \
- return (type *)jmap_get((const struct jmap *)map, index, 0); \
+ return (type *)jmap_get((const struct jmap *)map, idx, 0); \
} \
-static inline size_t jmap_##name##_popcount(const struct jmap_##name *map, \
- size_t start, size_t end_incl) \
+static inline unsigned long \
+jmap_##name##_popcount(const struct jmap_##name *map, \
+ unsigned long start, unsigned long end_incl) \
{ \
return jmap_popcount((const struct jmap *)map, start, end_incl); \
} \
-static inline size_t jmap_##name##_nth(const struct jmap_##name *map, \
- size_t n, size_t invalid) \
+static inline unsigned long jmap_##name##_nth(const struct jmap_##name *map, \
+ unsigned long n, \
+ unsigned long invalid) \
{ \
return jmap_nth((const struct jmap *)map, n, invalid); \
} \
-static inline size_t jmap_##name##_first(const struct jmap_##name *map, \
- size_t invalid) \
+static inline unsigned long \
+jmap_##name##_first(const struct jmap_##name *map, \
+ unsigned long invalid) \
{ \
return jmap_first((const struct jmap *)map, invalid); \
} \
-static inline size_t jmap_##name##_next(const struct jmap_##name *map, \
- size_t prev, size_t invalid) \
+static inline unsigned long \
+jmap_##name##_next(const struct jmap_##name *map, \
+ unsigned long prev, unsigned long invalid) \
{ \
return jmap_next((const struct jmap *)map, prev, invalid); \
} \
-static inline size_t jmap_##name##_last(const struct jmap_##name *map, \
- size_t invalid) \
+static inline unsigned long \
+jmap_##name##_last(const struct jmap_##name *map, \
+ unsigned long invalid) \
{ \
return jmap_last((const struct jmap *)map, invalid); \
} \
-static inline size_t jmap_##name##_prev(const struct jmap_##name *map, \
- size_t prev, size_t invalid) \
+static inline unsigned long \
+jmap_##name##_prev(const struct jmap_##name *map, \
+ unsigned long prev, unsigned long invalid) \
{ \
return jmap_prev((const struct jmap *)map, prev, invalid); \
} \
static inline type **jmap_##name##_getval(const struct jmap_##name *map, \
- size_t index) \
+ unsigned long idx) \
{ \
- return (type **)jmap_getval((struct jmap *)map, index); \
+ return (type **)jmap_getval((struct jmap *)map, idx); \
} \
static inline void jmap_##name##_putval(struct jmap_##name *map, \
type ***p) \
{ \
- return jmap_putval((struct jmap *)map, (size_t **)p); \
+ return jmap_putval((struct jmap *)map, (unsigned long **)p); \
} \
static inline type **jmap_##name##_nthval(struct jmap_##name *map, \
- size_t n, size_t *index) \
+ unsigned long n, \
+ unsigned long *idx) \
{ \
- return (type **)jmap_nthval((struct jmap *)map, n, index); \
+ return (type **)jmap_nthval((struct jmap *)map, n, idx); \
} \
static inline type **jmap_##name##_firstval(const struct jmap_##name *map, \
- size_t *index) \
+ unsigned long *idx) \
{ \
- return (type **)jmap_firstval((const struct jmap *)map, index); \
+ return (type **)jmap_firstval((const struct jmap *)map, idx); \
} \
static inline type **jmap_##name##_nextval(const struct jmap_##name *map, \
- size_t *index) \
+ unsigned long *idx) \
{ \
- return (type **)jmap_nextval((const struct jmap *)map, index); \
+ return (type **)jmap_nextval((const struct jmap *)map, idx); \
} \
static inline type **jmap_##name##_lastval(const struct jmap_##name *map, \
- size_t *index) \
+ unsigned long *idx) \
{ \
- return (type **)jmap_lastval((const struct jmap *)map, index); \
+ return (type **)jmap_lastval((const struct jmap *)map, idx); \
} \
static inline type **jmap_##name##_prevval(const struct jmap_##name *map, \
- size_t *index) \
+ unsigned long *idx) \
{ \
- return (type **)jmap_prevval((const struct jmap *)map, index); \
+ return (type **)jmap_prevval((const struct jmap *)map, idx); \
}
/**
* JMAP_DEFINE_PTRIDX_TYPE - create a map of jmap ops for ptr->ptr map
- * @itype: a type whose pointers will index into the map.
+ * @itype: a type whose pointers will idx into the map.
* @type: a type whose pointers will be values in the map.
* @name: a name for all the functions to define (of form jmap_<name>_*)
*
* This macro defines a map of inline functions for typesafe and
- * convenient usage of a pointer-indexed Judy map of pointers. It is
- * assumed that a NULL pointer is never an index in the map, as
- * various functions return NULL for "invalid index". Similarly,
- * jmap_@name_get will return NULL if an index isn't valid, so NULL indices
+ * convenient usage of a pointer-idxed Judy map of pointers. It is
+ * assumed that a NULL pointer is never an idx in the map, as
+ * various functions return NULL for "invalid idx". Similarly,
+ * jmap_@name_get will return NULL if an idx isn't valid, so NULL indices
* are not recommended (though you can tell using jmap_@name_test).
*
- * Since the ordering is by index pointer value, it's generally quite useless.
+ * Since the ordering is by idx pointer value, it's generally quite useless.
* Thus we don't define order-specific functions, except first/next for
* traversal.
*
* const char *jmap_@name_error(struct jmap_@name *map);
*
* bool jmap_@name_add(const struct jmap_@name *map,
- * const itype *index, const type *value);
+ * const itype *idx, const type *value);
* bool jmap_@name_set(const struct jmap_@name *map,
- * const itype *index, const type *value);
- * bool jmap_@name_del(struct jmap_@name *map, const itype *index);
- * bool jmap_@name_test(const struct jmap_@name *map, const itype *index);
+ * const itype *idx, const type *value);
+ * bool jmap_@name_del(struct jmap_@name *map, const itype *idx);
+ * bool jmap_@name_test(const struct jmap_@name *map, const itype *idx);
*
- * type *jmap_@name_get(const struct jmap_@name *map, const itype *index);
+ * type *jmap_@name_get(const struct jmap_@name *map, const itype *idx);
* itype *jmap_@name_count(const struct jmap_@name *map);
* itype *jmap_@name_first(const struct jmap_@name *map);
* itype *jmap_@name_next(const struct jmap_@name *map,
* const itype *prev);
*
* type **jmap_@name_getval(const struct jmap_@name *map,
- * const itype *index);
+ * const itype *idx);
* void jmap_@name_putval(struct jmap_@name *map, type ***p);
* type **jmap_@name_firstval(const struct jmap_@name *map,
- * const itype **index);
+ * const itype **idx);
* type **jmap_@name_nextval(const struct jmap_@name *map,
- * const itype **index);
+ * const itype **idx);
*/
#define JMAP_DEFINE_PTRIDX_TYPE(itype, type, name) \
struct jmap_##name; \
return jmap_error((struct jmap *)map); \
} \
static inline bool jmap_##name##_add(struct jmap_##name *map, \
- const itype *index, const type *value) \
+ const itype *idx, const type *value) \
{ \
- return jmap_add((struct jmap *)map, (size_t)index, \
- (size_t)value); \
+ return jmap_add((struct jmap *)map, (unsigned long)idx, \
+ (unsigned long)value); \
} \
static inline bool jmap_##name##_set(const struct jmap_##name *map, \
- const itype *index, const type *value) \
+ const itype *idx, const type *value) \
{ \
- return jmap_set((const struct jmap *)map, (size_t)index, \
- (size_t)value); \
+ return jmap_set((const struct jmap *)map, (unsigned long)idx, \
+ (unsigned long)value); \
} \
static inline bool jmap_##name##_del(struct jmap_##name *map, \
- const itype *index) \
+ const itype *idx) \
{ \
- return jmap_del((struct jmap *)map, (size_t)index); \
+ return jmap_del((struct jmap *)map, (unsigned long)idx); \
} \
static inline bool jmap_##name##_test(const struct jmap_##name *map, \
- const itype *index) \
+ const itype *idx) \
{ \
- return jmap_test((const struct jmap *)map, (size_t)index); \
+ return jmap_test((const struct jmap *)map, (unsigned long)idx); \
} \
static inline type *jmap_##name##_get(const struct jmap_##name *map, \
- const itype *index) \
+ const itype *idx) \
{ \
- return (type *)jmap_get((const struct jmap *)map, (size_t)index, 0); \
+ return (type *)jmap_get((const struct jmap *)map, \
+ (unsigned long)idx, 0); \
} \
-static inline size_t jmap_##name##_count(const struct jmap_##name *map) \
+static inline unsigned long \
+jmap_##name##_count(const struct jmap_##name *map) \
{ \
return jmap_popcount((const struct jmap *)map, 0, -1); \
} \
static inline itype *jmap_##name##_next(const struct jmap_##name *map, \
const itype *prev) \
{ \
- return (itype *)jmap_next((const struct jmap *)map, (size_t)prev, 0); \
+ return (itype *)jmap_next((const struct jmap *)map, \
+ (unsigned long)prev, 0); \
} \
static inline type **jmap_##name##_getval(const struct jmap_##name *map, \
- const itype *index) \
+ const itype *idx) \
{ \
- return (type **)jmap_getval((struct jmap *)map, (size_t)index); \
+ return (type **)jmap_getval((struct jmap *)map, \
+ (unsigned long)idx); \
} \
static inline void jmap_##name##_putval(struct jmap_##name *map, \
type ***p) \
{ \
- return jmap_putval((struct jmap *)map, (size_t **)p); \
+ return jmap_putval((struct jmap *)map, (unsigned long **)p); \
} \
static inline type **jmap_##name##_firstval(const struct jmap_##name *map, \
- itype **index) \
+ itype **idx) \
{ \
- return (type **)jmap_firstval((const struct jmap *)map, \
- (size_t *)index); \
+ unsigned long i; \
+ type **ret; \
+ ret = (type **)jmap_firstval((const struct jmap *)map, &i); \
+ *idx = (void *)i; \
+ return ret; \
} \
static inline type **jmap_##name##_nextval(const struct jmap_##name *map, \
- itype **index) \
+ itype **idx) \
{ \
return (type **)jmap_nextval((const struct jmap *)map, \
- (size_t *)index); \
+ (unsigned long *)idx); \
}
#endif /* CCAN_JMAP_TYPE_H */