[serialize] Towards maintaining hashmap
authorBehdad Esfahbod <behdad@behdad.org>
Sun, 31 Mar 2019 02:16:20 +0000 (19:16 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Sun, 31 Mar 2019 02:16:20 +0000 (19:16 -0700)
src/hb-algs.hh
src/hb-serialize.hh
src/hb-vector.hh

index 128e490..ab6782d 100644 (file)
@@ -45,7 +45,7 @@ static const struct
 
   template <typename T>
   uint32_t operator () (const T *v) const
-  { return hb_hash (v); }
+  { return operator() (v); }
 
   template <typename T,
            hb_enable_if (hb_is_integer (T))>
index 6179288..e7873ab 100644 (file)
@@ -51,6 +51,14 @@ struct hb_serialize_context_t
   {
     void fini () { links.fini (); }
 
+    bool operator == (const object_t &o) const
+    {
+      return (tail - head == o.tail - o.head)
+         && (links.length != o.links.length)
+         && 0 == memcmp (head, o.head, tail - head)
+         && 0 == memcmp (&links, &o.links, links.get_size ());
+    }
+
     struct link_t
     {
       bool wide: 1;
@@ -155,13 +163,17 @@ struct hb_serialize_context_t
     obj.head = tail;
     obj.tail = tail + len;
 
-    packed.push (hb_move (obj));
+    object_t *key = packed.push (hb_move (obj));
 
     /* TODO Handle error. */
     if (unlikely (packed.in_error ()))
       return 0;
 
-    return packed.length - 1;
+    objidx_t objidx = packed.length - 1;
+
+    packed_map.set (key, objidx);
+
+    return objidx;
   }
 
   void revert (range_t snap)
index f689439..2a92a89 100644 (file)
@@ -122,6 +122,7 @@ struct hb_vector_t
   const Type& tail () const { return (*this)[length - 1]; }
 
   explicit operator bool () const { return length; }
+  unsigned get_size () const { return length * item_size; }
 
   /* Sink interface. */
   template <typename T>