···
use std::collections::VecDeque;
3
+
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;
150
-
(x, y + b.clone() + c.clone())
152
-
(a.clone(), b.clone() + c.clone())
} else if n - a.len() < b.len() {
let (x, y) = b.split(n - a.len());
155
-
(a.clone() + x, y + c.clone())
} else if n == a.len() + b.len() {
157
-
(a.clone() + b.clone(), c.clone())
let (x, y) = c.split(n - a.len() - b.len());
160
-
(a.clone() + b.clone() + x, y)
···
284
-
fn add_helper(lhs: DnaRef, rhs: DnaRef) -> AddState {
285
+
fn add_helper(lhs: &DnaRef, rhs: &DnaRef) -> AddState {
if lhs.depth() == rhs.depth() {
286
-
AddState::Two(lhs, rhs)
287
+
AddState::Two(lhs.clone(), rhs.clone())
} else if lhs.depth() < rhs.depth() {
Dna::Empty => unreachable!(),
290
-
Dna::Leaf(_) => AddState::One(rhs),
291
+
Dna::Leaf(_) => AddState::One(rhs.clone()),
let (a, b) = &node.children;
293
-
match add_helper(lhs, a.clone()) {
294
+
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;
302
-
match add_helper(lhs, a.clone()) {
303
+
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;
319
-
match add_helper(b.clone(), rhs) {
320
+
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;
328
-
match add_helper(c.clone(), rhs) {
329
+
match add_helper(c, rhs) {
AddState::One(DnaRef::from_three_children(a.clone(), b.clone(), x))
···
342
-
impl Add for DnaRef {
343
-
type Output = Self;
343
+
impl Add<DnaRef> for DnaRef {
344
+
type Output = DnaRef;
346
+
fn add(self, other: DnaRef) -> DnaRef {
347
+
match add_helper(&self, &other) {
348
+
AddState::One(a) => a,
349
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
345
-
fn add(self, other: Self) -> Self {
354
+
impl Add<&DnaRef> for DnaRef {
355
+
type Output = DnaRef;
357
+
fn add(self, other: &DnaRef) -> DnaRef {
358
+
match add_helper(&self, other) {
359
+
AddState::One(a) => a,
360
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
365
+
impl Add<DnaRef> for &DnaRef {
366
+
type Output = DnaRef;
368
+
fn add(self, other: DnaRef) -> DnaRef {
369
+
match add_helper(self, &other) {
370
+
AddState::One(a) => a,
371
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
376
+
impl Add<&DnaRef> for &DnaRef {
377
+
type Output = DnaRef;
379
+
fn add(self, other: &DnaRef) -> DnaRef {
match add_helper(self, other) {
348
-
AddState::Two(a, b) => Self::from_two_children(a, b),
382
+
AddState::Two(a, b) => DnaRef::from_two_children(a, b),
387
+
impl AddAssign<DnaRef> for DnaRef {
388
+
fn add_assign(&mut self, other: DnaRef) {
389
+
match add_helper(self, &other) {
390
+
AddState::One(a) => {
393
+
AddState::Two(a, b) => {
394
+
*self = Self::from_two_children(a, b);
400
+
impl AddAssign<&DnaRef> for DnaRef {
401
+
fn add_assign(&mut self, other: &DnaRef) {
402
+
match add_helper(self, other) {
403
+
AddState::One(a) => {
406
+
AddState::Two(a, b) => {
407
+
*self = Self::from_two_children(a, b);