dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] id_table: wip - use ID shift
Date: Wed,  4 Nov 2015 21:04:43 +0000	[thread overview]
Message-ID: <20151104210443.30958-1-e@80x24.org> (raw)

This allows all IDs, including ivar IDs to be used in id_table
while (hopefully) preserving good behavior without the scope
bits hurting hashing.
---
 id_table.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/id_table.c b/id_table.c
index 13adf6b..37f26fa 100644
--- a/id_table.c
+++ b/id_table.c
@@ -30,10 +30,11 @@
  *   33: array(12) (capa <= 64) + hash(22)
  *   34: array(14) (capa <= 64) + hash(22)
  *   34: array(15) (capa <= 64) + hash(22)
+ *   44: array(15) (capa <= 64) + hash(22), but shifted IDs
  */
 
 #ifndef ID_TABLE_IMPL
-#define ID_TABLE_IMPL 34
+#define ID_TABLE_IMPL 44
 #endif
 
 #if ID_TABLE_IMPL == 0
@@ -179,6 +180,20 @@
 
 #define ID_TABLE_USE_SMALL_HASH 1
 
+#elif ID_TABLE_IMPL == 44
+#define ID_TABLE_NAME mix
+#define ID_TABLE_IMPL_TYPE struct mix_id_table
+
+#define ID_TABLE_USE_MIX 1
+#define ID_TABLE_USE_MIX_LIST_MAX_CAPA 64
+
+#define ID_TABLE_USE_ID_SHIFT 1
+
+#define ID_TABLE_USE_LIST 1
+#define ID_TABLE_USE_CALC_VALUES 1
+#define ID_TABLE_USE_LIST_SORTED 1
+
+#define ID_TABLE_USE_SMALL_HASH 1
 #else
 #error
 #endif
@@ -208,7 +223,22 @@ UNUSED(int IMPL(_delete)(ID_TABLE_IMPL_TYPE *, ID));
 UNUSED(void IMPL(_foreach)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_func_t *, void *));
 UNUSED(void IMPL(_foreach_values)(ID_TABLE_IMPL_TYPE *, rb_id_table_foreach_values_func_t *, void *));
 
-#if ID_TABLE_USE_ID_SERIAL
+#if ID_TABLE_USE_ID_SHIFT
+typedef ID id_key_t;
+#define ID_LBITS ((CHAR_BIT * sizeof(ID)) - ID_SCOPE_SHIFT)
+
+static inline ID
+key2id(id_key_t key)
+{
+    return (key << ID_SCOPE_SHIFT) | (key >> ID_LBITS);
+}
+
+static inline id_key_t
+id2key(ID id)
+{
+    return (id << ID_LBITS) | (id >> ID_SCOPE_SHIFT);
+}
+#elif ID_TABLE_USE_ID_SERIAL
 typedef rb_id_serial_t id_key_t;
 static inline ID
 key2id(id_key_t key)
-- 
EW


                 reply	other threads:[~2015-11-04 21:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151104210443.30958-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).