fn lookup_insertion_point<Id: Hash + Clone + Eq + Debug>(
    tree: &Tree<Id>,
    lookup_id: &Id,
) -> Result<(NodeId, usize, usize), TreeError> {
    let node_id = tree.id_to_node(&lookup_id)?;
    let node = tree
        .nodes
        .get(&node_id)
        .expect("node_id listed in id_to_node did not exist.");
    if node.segment_is_container() {
        let (_, start) = node.segment_adjacencies();
        return Ok((*start, 0, 0));
    }
    let ids = node.segment_ids()?;

    let mut id_list_index_opt = None;
    for (i, (id, string_index_opt)) in ids.iter().enumerate() {
        if let Some(id_list_index) = id_list_index_opt {
            if let Some(string_index) = string_index_opt {
                return Ok((node_id, *string_index, id_list_index));
            }
        }
        if id == lookup_id {
            id_list_index_opt = Some(i + 1);
            // don't check for string index until next iteration of loop; we want the *next*
            // char index to be the insertion point, not this one
        }
    }
    if let Some(id_list_index) = id_list_index_opt {
        return Ok((node_id, node.segment_contents_len()?, id_list_index));
    }
    panic!("id not found in segment id list");
}
/// From a character id, looks up the `(containing segment id, character index, id list index)`
/// that an appended character would need to be inserted at
From a character id, looks up the `(containing segment id, character index, id list index)`
that an appended character would need to be inserted at
From a character id looks up the ` ( containing segment id character index id list index ) ` that an appended character would need to be inserted at
fn lookup_insertion_point<Id: Hash + Clone + Eq + Debug>(
    tree: &Tree<Id>,
    lookup_id: &Id,
) -> Result<(NodeId, usize, usize), TreeError> {
    let node_id = tree.id_to_node(&lookup_id)?;
    let node = tree
        .nodes
        .get(&node_id)
        .expect("node_id listed in id_to_node did not exist.");
    if node.segment_is_container() {
        let (_, start) = node.segment_adjacencies();
        return Ok((*start, 0, 0));
    }
    let ids = node.segment_ids()?;
    let mut id_list_index_opt = None;
    for (i, (id, string_index_opt)) in ids.iter().enumerate() {
        if let Some(id_list_index) = id_list_index_opt {
            if let Some(string_index) = string_index_opt {
                return Ok((node_id, *string_index, id_list_index));
            }
        }
        if id == lookup_id {
            id_list_index_opt = Some(i + 1);
            // don't check for string index until next iteration of loop; we want the *next*
            // char index to be the insertion point, not this one
        }
    }
    if let Some(id_list_index) = id_list_index_opt {
        return Ok((node_id, node.segment_contents_len()?, id_list_index));
    }
    panic!("id not found in segment id list");
}
fn lookup_insertion_point < Id : Hash + Clone + Eq + Debug > ( tree : & Tree < Id > , lookup_id : & Id , ) -> Result < ( NodeId , usize , usize ) , TreeError > { let node_id = tree . id_to_node ( & lookup_id ) ? ; let node = tree . nodes . get ( & node_id ) . expect ( " " ) ; if node . segment_is_container ( ) { let ( _ , start ) = node . segment_adjacencies ( ) ; return Ok ( ( * start , 0 , 0 ) ) ; } let ids = node . segment_ids ( ) ? ; let mut id_list_index_opt = None ; for ( i , ( id , string_index_opt ) ) in ids . iter ( ) . enumerate ( ) { if let Some ( id_list_index ) = id_list_index_opt { if let Some ( string_index ) = string_index_opt { return Ok ( ( node_id , * string_index , id_list_index ) ) ; } } if id == lookup_id { id_list_index_opt = Some ( i + 1 ) ; // don't check for string index until next iteration of loop; we want the *next* // char index to be the insertion point, not this one } } if let Some ( id_list_index ) = id_list_index_opt { return Ok ( ( node_id , node . segment_contents_len ( ) ? , id_list_index ) ) ; } panic ! ( " " ) ; }
From a character id, looks up the `(containing segment id, character index, id list index)`
that an appended character would need to be inserted at
From a character id looks up the ` ( containing segment id character index id list index ) ` that an appended character would need to be inserted at
tree
&Tree<Id>
lookup_id
&Id