operator hb_array_t<const Type> () { return hb_array_t<const Type> (arrayZ, length); }
template <typename T> operator T * () const { return arrayZ; }
+ bool operator == (const hb_array_t &o) const;
uint32_t hash () const;
/*
{ return hb_sorted_array_t<T> (array_); }
template <typename T>
+bool hb_array_t<T>::operator == (const hb_array_t<T> &o) const
+{
+ return length == o.length &&
+ + hb_zip (*this, o)
+ | hb_map ([] (hb_pair_t<T&, T&> &&_) -> bool { return _.first == _.second; })
+ | hb_all
+ ;
+}
+template <typename T>
uint32_t hb_array_t<T>::hash () const
{
return
typedef hb_array_t<const char> hb_bytes_t;
typedef hb_array_t<const unsigned char> hb_ubytes_t;
-/* TODO Specialize hashing for hb_bytes_t and hb_ubytes_t. */
+/* TODO Specialize opeator==/hash() for hb_bytes_t and hb_ubytes_t. */
//template <>
//uint32_t hb_array_t<const char>::hash () const { return 0; }
K key;
V value;
- bool operator== (K o) { return hb_deref_pointer (key) == hb_deref_pointer (o); }
- bool operator== (const item_t &o) { return *this == o.key; }
+ void clear () { key = kINVALID; value = vINVALID; }
+
+ bool operator == (K o) { return hb_deref_pointer (key) == hb_deref_pointer (o); }
+ bool operator == (const item_t &o) { return *this == o.key; }
bool is_unused () const { return key == kINVALID; }
bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
};
void reset ()
{
- /* TODO Keep array? */
- fini_shallow ();
- init_shallow ();
+ clear ();
}
bool in_error () const { return !successful; }
successful = false;
return false;
}
- memset (new_items, 0xFF, (size_t) new_size * sizeof (item_t));
+ + hb_iter (new_items, new_size)
+ | hb_apply ([] (item_t &_) { _.clear (); }) /* TODO make pointer-to-methods invokable. */
+ ;
unsigned int old_size = mask + 1;
item_t *old_items = items;
{
if (unlikely (!items)) return vINVALID;
unsigned int i = bucket_for (key);
- return items[i] == key ? items[i].value : vINVALID;
+ return !items[i].is_unused () && items[i] == key ? items[i].value : vINVALID;
}
void del (K key) { set (key, vINVALID); }
void clear ()
{
- if (items) memset (items, 0xFF, ((size_t) mask + 1) * sizeof (item_t));
+ if (items)
+ + hb_iter (items, mask + 1)
+ | hb_apply ([] (item_t &_) { _.clear (); }) /* TODO make pointer-to-methods invokable. */
+ ;
+
population = occupancy = 0;
}
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 ());
+ && (links.length == o.links.length)
+ && 0 == hb_memcmp (head, o.head, tail - head)
+ && links.as_bytes () == o.links.as_bytes ();
}
uint32_t hash () const
{
objidx = packed.length - 1;
- if (0) // XXX
packed_map.set (key, objidx);
return objidx;
while (packed.length > 1 &&
packed.tail ().head < tail)
{
- if (0) // XXX
packed_map.del (&packed.tail ());
packed.pop ();
}
hb_bytes_t as_bytes () const { return hb_bytes_t ((const char *) arrayZ_,
length * item_size); }
+ bool operator == (const hb_vector_t &o) const { return as_bytes () == o.as_bytes (); }
uint32_t hash () const { return as_bytes ().hash (); }
const Type * arrayZ () const { return arrayZ_; }