-/* Accessors for each type of encoding */
-#define INTSET_VALUE_ENCODING(__val) (((__val) < INT32_MIN || (__val) > INT32_MAX) ? \
- INTSET_ENC_INT64 : (((__val) < INT16_MIN || (__val) > INT16_MAX) ? \
- INTSET_ENC_INT32 : INTSET_ENC_INT16))
-#define INTSET_GET_ENCODED(__is,__pos,__enc) ((__enc == INTSET_ENC_INT64) ? \
- ((int64_t*)(__is)->contents)[__pos] : ((__enc == INTSET_ENC_INT32) ? \
- ((int32_t*)(__is)->contents)[__pos] : ((int16_t*)(__is)->contents)[__pos]))
-#define INTSET_GET(__is,__pos) (INTSET_GET_ENCODED(__is,__pos,(__is)->encoding))
-#define INTSET_SET(__is,__pos,__val) { \
- if ((__is)->encoding == INTSET_ENC_INT64) \
- ((int64_t*)(__is)->contents)[__pos] = (__val); \
- else if ((__is)->encoding == INTSET_ENC_INT32) \
- ((int32_t*)(__is)->contents)[__pos] = (__val); \
- else \
- ((int16_t*)(__is)->contents)[__pos] = (__val); }
+/* Return the required encoding for the provided value. */
+static uint8_t _intsetValueEncoding(int64_t v) {
+ if (v < INT32_MIN || v > INT32_MAX)
+ return INTSET_ENC_INT64;
+ else if (v < INT16_MIN || v > INT16_MAX)
+ return INTSET_ENC_INT32;
+ return INTSET_ENC_INT16;
+}
+
+/* Return the value at pos, given an encoding. */
+static int64_t _intsetGetEncoded(intset *is, int pos, uint8_t enc) {
+ if (enc == INTSET_ENC_INT64)
+ return ((int64_t*)is->contents)[pos];
+ else if (enc == INTSET_ENC_INT32)
+ return ((int32_t*)is->contents)[pos];
+ return ((int16_t*)is->contents)[pos];
+}
+
+/* Return the value at pos, using the configured encoding. */
+static int64_t _intsetGet(intset *is, int pos) {
+ return _intsetGetEncoded(is,pos,is->encoding);
+}
+
+/* Set the value at pos, using the configured encoding. */
+static void _intsetSet(intset *is, int pos, int64_t value) {
+ if (is->encoding == INTSET_ENC_INT64)
+ ((int64_t*)is->contents)[pos] = value;
+ else if (is->encoding == INTSET_ENC_INT32)
+ ((int32_t*)is->contents)[pos] = value;
+ else
+ ((int16_t*)is->contents)[pos] = value;
+}