···
use std::collections::VecDeque;
···
let (a, b) = &node.children;
let (x, y) = b.split(n - a.len());
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
-
(x, y + b.clone() + c.clone())
-
(a.clone(), b.clone() + c.clone())
} else if n - a.len() < b.len() {
let (x, y) = b.split(n - a.len());
-
(a.clone() + x, y + c.clone())
} else if n == a.len() + b.len() {
-
(a.clone() + b.clone(), c.clone())
let (x, y) = c.split(n - a.len() - b.len());
-
(a.clone() + b.clone() + x, y)
···
-
fn add_helper(lhs: DnaRef, rhs: DnaRef) -> AddState {
if lhs.depth() == rhs.depth() {
-
AddState::Two(lhs, rhs)
} else if lhs.depth() < rhs.depth() {
Dna::Empty => unreachable!(),
-
Dna::Leaf(_) => AddState::One(rhs),
let (a, b) = &node.children;
-
match add_helper(lhs, a.clone()) {
AddState::One(x) => AddState::One(DnaRef::from_two_children(x, b.clone())),
AddState::One(DnaRef::from_three_children(x, y, b.clone()))
···
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
-
match add_helper(lhs, a.clone()) {
AddState::One(DnaRef::from_three_children(x, b.clone(), c.clone()))
···
Dna::Empty => unreachable!(),
Dna::Leaf(_) => AddState::One(lhs.clone()),
let (a, b) = &node.children;
-
match add_helper(b.clone(), rhs) {
AddState::One(x) => AddState::One(DnaRef::from_two_children(a.clone(), x)),
AddState::One(DnaRef::from_three_children(a.clone(), x, y))
···
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
-
match add_helper(c.clone(), rhs) {
AddState::One(DnaRef::from_three_children(a.clone(), b.clone(), x))
···
-
fn add(self, other: Self) -> Self {
match add_helper(self, other) {
-
AddState::Two(a, b) => Self::from_two_children(a, b),
···
use std::collections::VecDeque;
+
use std::ops::AddAssign;
···
let (a, b) = &node.children;
let (x, y) = b.split(n - a.len());
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
} else if n - a.len() < b.len() {
let (x, y) = b.split(n - a.len());
} else if n == a.len() + b.len() {
let (x, y) = c.split(n - a.len() - b.len());
···
+
fn add_helper(lhs: &DnaRef, rhs: &DnaRef) -> AddState {
if lhs.depth() == rhs.depth() {
+
AddState::Two(lhs.clone(), rhs.clone())
} else if lhs.depth() < rhs.depth() {
Dna::Empty => unreachable!(),
+
Dna::Leaf(_) => AddState::One(rhs.clone()),
let (a, b) = &node.children;
+
match add_helper(lhs, a) {
AddState::One(x) => AddState::One(DnaRef::from_two_children(x, b.clone())),
AddState::One(DnaRef::from_three_children(x, y, b.clone()))
···
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
+
match add_helper(lhs, a) {
AddState::One(DnaRef::from_three_children(x, b.clone(), c.clone()))
···
Dna::Empty => unreachable!(),
Dna::Leaf(_) => AddState::One(lhs.clone()),
let (a, b) = &node.children;
+
match add_helper(b, rhs) {
AddState::One(x) => AddState::One(DnaRef::from_two_children(a.clone(), x)),
AddState::One(DnaRef::from_three_children(a.clone(), x, y))
···
Dna::ThreeNode(node) => {
let (a, b, c) = &node.children;
+
match add_helper(c, rhs) {
AddState::One(DnaRef::from_three_children(a.clone(), b.clone(), x))
···
+
impl Add<DnaRef> for DnaRef {
+
fn add(self, other: DnaRef) -> DnaRef {
+
match add_helper(&self, &other) {
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
+
impl Add<&DnaRef> for DnaRef {
+
fn add(self, other: &DnaRef) -> DnaRef {
+
match add_helper(&self, other) {
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
+
impl Add<DnaRef> for &DnaRef {
+
fn add(self, other: DnaRef) -> DnaRef {
+
match add_helper(self, &other) {
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
+
impl Add<&DnaRef> for &DnaRef {
+
fn add(self, other: &DnaRef) -> DnaRef {
match add_helper(self, other) {
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
+
impl AddAssign<DnaRef> for DnaRef {
+
fn add_assign(&mut self, other: DnaRef) {
+
match add_helper(self, &other) {
+
AddState::Two(a, b) => {
+
*self = Self::from_two_children(a, b);
+
impl AddAssign<&DnaRef> for DnaRef {
+
fn add_assign(&mut self, other: &DnaRef) {
+
match add_helper(self, other) {
+
AddState::Two(a, b) => {
+
*self = Self::from_two_children(a, b);