positional-based utility methods we consider nonexistent child to be trivially black def set red(selfp) node red true def set black(selfp) node red false def set color(selfpmake red) node red make red def is red(selfp)return is not none and node red def is red leaf(selfp)return self is red(pand self is leaf(pdef get red child(selfp)"""return red child of (or none if no such child""for child in (self left( )self right( ))if self is red(child)return child return none support for insertions def rebalance insert(selfp)new node is always red self resolve red(pdef resolve red(selfp)if self is root( )self set black(pelseparent self parent(pif self is red(parent)uncle self sibling(parentif not self is red(uncle)middle self restructure(pself set black(middleself set red(self left(middle)self set red(self right(middle)elsegrand self parent(parentself set red(grandself set black(self left(grand)self set black(self right(grand)self resolve red(grandmake root black double red problem case misshapen -node do trinode restructuring and then fix colors case overfull -node grandparent becomes red its children become black recur at red grandparent code fragment continuation of the redblacktreemap class (continued from code fragment and concluded in code fragment