This commit is contained in:
		@@ -76,29 +76,30 @@ pub fn insert(list: DLList(a), val: a) -> DLList(a) {
 | 
				
			|||||||
      DLList(ref + 1, ref, dict.insert(list.mem, ref, node))
 | 
					      DLList(ref + 1, ref, dict.insert(list.mem, ref, node))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    False -> {
 | 
					    False -> {
 | 
				
			||||||
      let assert Ok(curr_node) = dict.get(list.mem, list.current)
 | 
					      let assert Ok(curr_node) = get_curr_node(list)
 | 
				
			||||||
      let curr_node_2 = Node(..curr_node, right: ref)
 | 
					 | 
				
			||||||
      let next = curr_node.right
 | 
					      let next = curr_node.right
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      let next_node = case next == list.current {
 | 
					      let next_node = case next == list.current {
 | 
				
			||||||
        True -> Ok(curr_node_2)
 | 
					        True -> Ok(Node(..curr_node, right: ref))
 | 
				
			||||||
        False -> dict.get(list.mem, next)
 | 
					        False -> dict.get(list.mem, next)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      let new_mem = case next == list.current {
 | 
					      let new_mem = case next == list.current {
 | 
				
			||||||
        True -> list.mem
 | 
					        True -> list.mem
 | 
				
			||||||
        False -> dict.insert(list.mem, list.current, curr_node_2)
 | 
					        False ->
 | 
				
			||||||
 | 
					          dict.insert(list.mem, list.current, Node(..curr_node, right: ref))
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      let new_mem = case next_node {
 | 
					      let new_mem = case next_node {
 | 
				
			||||||
        Ok(next_node) -> {
 | 
					        Ok(next_node) -> {
 | 
				
			||||||
          let next_node_2 = Node(..next_node, left: ref)
 | 
					          dict.insert(new_mem, next, Node(..next_node, left: ref))
 | 
				
			||||||
          dict.insert(new_mem, next, next_node_2)
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Error(_) -> new_mem
 | 
					        Error(_) -> new_mem
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      let new_node = Node(val, list.current, next)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      let new_mem = dict.insert(new_mem, ref, new_node)
 | 
					      DLList(
 | 
				
			||||||
      DLList(list.counter + 1, list.counter, new_mem)
 | 
					        counter: list.counter + 1,
 | 
				
			||||||
 | 
					        current: list.counter,
 | 
				
			||||||
 | 
					        mem: dict.insert(new_mem, ref, Node(val, list.current, next)),
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -211,8 +212,10 @@ fn take_loop(list: DLList(a), n_times: Int, acc: List(a)) -> List(a) {
 | 
				
			|||||||
  case n_times {
 | 
					  case n_times {
 | 
				
			||||||
    0 -> list.reverse(acc)
 | 
					    0 -> list.reverse(acc)
 | 
				
			||||||
    n -> {
 | 
					    n -> {
 | 
				
			||||||
      let assert Ok(item) = get(list)
 | 
					      case get(list) {
 | 
				
			||||||
      take_loop(move_right(list), n - 1, [item, ..acc])
 | 
					        Error(_) -> []
 | 
				
			||||||
 | 
					        Ok(item) -> take_rev_loop(move_right(list), n - 1, [item, ..acc])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -226,8 +229,10 @@ fn take_rev_loop(list: DLList(a), n_times: Int, acc: List(a)) -> List(a) {
 | 
				
			|||||||
  case n_times {
 | 
					  case n_times {
 | 
				
			||||||
    0 -> list.reverse(acc)
 | 
					    0 -> list.reverse(acc)
 | 
				
			||||||
    n -> {
 | 
					    n -> {
 | 
				
			||||||
      let assert Ok(item) = get(list)
 | 
					      case get(list) {
 | 
				
			||||||
      take_rev_loop(move_left(list), n - 1, [item, ..acc])
 | 
					        Error(_) -> []
 | 
				
			||||||
 | 
					        Ok(item) -> take_rev_loop(move_left(list), n - 1, [item, ..acc])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -236,8 +241,10 @@ pub fn to_list(list: DLList(a)) -> List(a) {
 | 
				
			|||||||
  case is_empty(list) {
 | 
					  case is_empty(list) {
 | 
				
			||||||
    True -> []
 | 
					    True -> []
 | 
				
			||||||
    False -> {
 | 
					    False -> {
 | 
				
			||||||
      let assert Ok(a) = get(list)
 | 
					      case get(list) {
 | 
				
			||||||
      [a, ..to_list_loop(do_move_right(list), list.current)]
 | 
					        Error(_) -> []
 | 
				
			||||||
 | 
					        Ok(val) -> [val, ..to_list_loop(do_move_right(list), list.current)]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -247,22 +254,31 @@ fn to_list_loop(list: Result(DLList(a), Nil), start_ref: Int) -> List(a) {
 | 
				
			|||||||
    Error(_) -> []
 | 
					    Error(_) -> []
 | 
				
			||||||
    Ok(DLList(_, current, _)) if current == start_ref -> []
 | 
					    Ok(DLList(_, current, _)) if current == start_ref -> []
 | 
				
			||||||
    Ok(list) -> {
 | 
					    Ok(list) -> {
 | 
				
			||||||
      let assert Ok(a) = get(list)
 | 
					      case get(list) {
 | 
				
			||||||
      [a, ..to_list_loop(do_move_right(list), start_ref)]
 | 
					        Error(_) -> []
 | 
				
			||||||
 | 
					        Ok(val) -> [val, ..to_list_loop(do_move_right(list), start_ref)]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn update(list: DLList(a), value: a) -> Result(DLList(a), Nil) {
 | 
					pub fn update(list: DLList(a), value: a) -> Result(DLList(a), Nil) {
 | 
				
			||||||
  use <- bool.guard(when: is_empty(list), return: Error(Nil))
 | 
					  use <- bool.guard(when: is_empty(list), return: Error(Nil))
 | 
				
			||||||
  let assert Ok(curr_node) = get_curr_node(list)
 | 
					  case get_curr_node(list) {
 | 
				
			||||||
 | 
					    Error(_) -> Error(Nil)
 | 
				
			||||||
 | 
					    Ok(curr_node) ->
 | 
				
			||||||
      Ok(
 | 
					      Ok(
 | 
				
			||||||
        DLList(
 | 
					        DLList(
 | 
				
			||||||
          ..list,
 | 
					          ..list,
 | 
				
			||||||
      mem: dict.insert(list.mem, list.current, Node(..curr_node, val: value)),
 | 
					          mem: dict.insert(
 | 
				
			||||||
 | 
					            list.mem,
 | 
				
			||||||
 | 
					            list.current,
 | 
				
			||||||
 | 
					            Node(..curr_node, val: value),
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn update_dict_entry(
 | 
					fn update_dict_entry(
 | 
				
			||||||
  list: dict.Dict(Int, Node(a)),
 | 
					  list: dict.Dict(Int, Node(a)),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user