# [PATCH 26/94] Maple Tree: Add new data structure

Fri May 14 06:42:04 PDT 2021

```On Wed, Apr 28, 2021 at 03:36:02PM +0000, Liam Howlett wrote:
> +/*
> + * mte_set_parent() - Set the parent node and encode the slot.
> + * @enode: The encoded maple node.
> + * @parent: The encoded maple node that is the parent of @enode.
> + * @slot: The slot that @enode resides in @parent.
> + *
> + * Type is encoded in the enode->parent
> + * bit 0: 1 = root, 0 otherwise
> + * bit 1: Reserved.
> + * bit 2: 0 = range 32, 1 = [a]range 64
> + *
> + * Slot number is encoded in the enode->parent
> + * range_32, slot number is encoded in bits 3-6
> + * [a]range_64, slot number is encoded in bits 3-6
> + */
> +static inline void mte_set_parent(struct maple_enode *enode,
> +				 const struct maple_enode *parent,
> +				 unsigned char slot)
> +{
> +	unsigned long bitmask = 0x78;
> +	unsigned long val = (unsigned long) parent;
> +	unsigned long type = 0;
> +
> +	switch (mte_node_type(parent)) {
> +	case maple_range_64:
> +	case maple_arange_64:
> +		type = 6;

6 = 4 + 2, which has bit1 set, but the above sayeth bit1 is reserved.

It is also mighty confusing to have two different type fields, is there
no way we can merge the types into a single (shared) space?

> +		break;
> +	default:
> +		break;
> +	}
> +
> +	val &= ~bitmask; // Remove any old slot number.
> +	val |= (slot << MAPLE_PARENT_SHIFT); // Set the slot.
> +	val |= type;
> +	mte_to_node(enode)->parent = ma_parent_ptr(val);
> +}

```