+
+
+/***************************************************************
+ * Singleton encoding
+ ***************************************************************/
+/* When there is only a single item, we don't allocate a block
+ * for it, but code it in the directory entry directly, if it
+ * fits.
+ */
+
+#define DEC_SYSBITS 15
+#define DEC_SEQBITS 15
+#define DEC_MASK(n) ((1<<(n))-1)
+
+int is_singleton(ISAMD_P ipos)
+{
+ return ( ipos != 0 ) && ( ipos & 1 );
+}
+
+
+int singleton_encode(struct it_key *k)
+/* encodes the key into one int. If it does not fit, returns 0 */
+{
+ if ( (k->sysno & DEC_MASK(DEC_SYSBITS) ) != k->sysno )
+ return 0; /* no room dor sysno */
+ if ( (k->seqno & DEC_MASK(DEC_SYSBITS) ) != k->seqno )
+ return 0; /* no room dor sysno */
+ return ( (k->sysno | (k->seqno << DEC_SYSBITS) ) << 1) | 1;
+}
+
+void singleton_decode (int code, struct it_key *k)
+{
+ assert ((code & 1) == 1 );
+ code = code >> 1;
+ k->sysno = code & DEC_MASK(DEC_SYSBITS);
+ k->seqno = code >> DEC_SYSBITS ;
+}
+
+