pub fn try_merge_key(key1: &SortKey<'a>, key2: &SortKey<'a>) -> Option<SortKey<'a>> {
        if key1.is_empty() || key2.is_empty() {
            panic!("Sort key cannot be empty");
        }

        let key1 = key1.clone();
        let key2 = key2.clone();

        // Verify if time column in the sort key
        match key1.columns.get_index_of(TIME_COLUMN_NAME) {
            None => panic!("Time column is not included in the sort key {:#?}", key1),
            Some(idx) => {
                if idx < key1.len() - 1 {
                    panic!("Time column is not last in the sort key {:#?}", key1)
                }
            }
        }
        match key2.columns.get_index_of(TIME_COLUMN_NAME) {
            None => panic!("Time column is not included in the sort key {:#?}", key2),
            Some(idx) => {
                if idx < key2.len() - 1 {
                    panic!("Time column is not last in the sort key {:#?}", key2)
                }
            }
        }

        let (long_key, short_key) = if key1.len() > key2.len() {
            (key1, key2)
        } else {
            (key2, key1)
        };

        // Go over short key and check its right-order availability in the long key
        let mut prev_long_idx: Option<usize> = None;
        for (col, sort_options) in &short_key.columns {
            if let Some(long_idx) = long_key.find_index(col, sort_options) {
                match prev_long_idx {
                    None => prev_long_idx = Some(long_idx),
                    Some(prev_idx) => {
                        if long_idx > prev_idx {
                            // In the right order, update the current idx
                            prev_long_idx = Some(long_idx);
                        } else {
                            // Not in the right order
                            return None;
                        }
                    }
                }
            } else {
                // Not found
                return None;
            }
        }

        // Reach here means the long key is the super key of the sort one
        Some(long_key)
    }
/// Returns merge key of the 2 given keys if one covers the other. Returns None otherwise.
/// Key1 is said to cover key2 if key2 is a subset and in the same order of key1.
/// Examples:
///   . (a) covers empty and (a)  =>
///         . super key of (a) and empty is (a)
///         . super key of (a) and (a)) is (a)
///   . (a, b) covers empty, (a), (b), and (a, b) =>
///         . super key of (a, b) and empty is (a, b)
///         . super key of (a, b) and (a) is (a, b)
///         . super key of (a, b) and (b) is (a, b)
///         . super key of (a, b) and (a, b) is (a, b)
///   . (a, b) does not cover (b, a) => super key of (a, b) and (b, a) is None
///   . (a, b, c) covers (a, b), (a, c), (b, c), (a), (b), (c) and empty =>
///        super key of (a, b, c) and any of { (a, b), (a, c), (b, c), (a), (b), (c) and empty } is (a, b, c)
///   . (a, b, c) does not cover (b, a), (c, a), (c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a) =>
///        super key of (a, b, c) and any of { b, a), (c, a), (c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a) } is None
///
///  Note that the last column in the sort key must be time
Returns merge key of the 2 given keys if one covers the other. Returns None otherwise.
Key1 is said to cover key2 if key2 is a subset and in the same order of key1.

Note that the last column in the sort key must be time
Returns merge key of the 2 given keys if one covers the other . Returns None otherwise . Key1 is said to cover key2 if key2 is a subset and in the same order of key1 . Note that the last column in the sort key must be time
pub fn try_merge_key(key1: &SortKey<'a>, key2: &SortKey<'a>) -> Option<SortKey<'a>> {
        if key1.is_empty() || key2.is_empty() {
            panic!("Sort key cannot be empty");
        }
        let key1 = key1.clone();
        let key2 = key2.clone();
        // Verify if time column in the sort key
        match key1.columns.get_index_of(TIME_COLUMN_NAME) {
            None => panic!("Time column is not included in the sort key {:#?}", key1),
            Some(idx) => {
                if idx < key1.len() - 1 {
                    panic!("Time column is not last in the sort key {:#?}", key1)
                }
            }
        }
        match key2.columns.get_index_of(TIME_COLUMN_NAME) {
            None => panic!("Time column is not included in the sort key {:#?}", key2),
            Some(idx) => {
                if idx < key2.len() - 1 {
                    panic!("Time column is not last in the sort key {:#?}", key2)
                }
            }
        }
        let (long_key, short_key) = if key1.len() > key2.len() {
            (key1, key2)
        } else {
            (key2, key1)
        };
        // Go over short key and check its right-order availability in the long key
        let mut prev_long_idx: Option<usize> = None;
        for (col, sort_options) in &short_key.columns {
            if let Some(long_idx) = long_key.find_index(col, sort_options) {
                match prev_long_idx {
                    None => prev_long_idx = Some(long_idx),
                    Some(prev_idx) => {
                        if long_idx > prev_idx {
                            // In the right order, update the current idx
                            prev_long_idx = Some(long_idx);
                        } else {
                            // Not in the right order
                            return None;
                        }
                    }
                }
            } else {
                // Not found
                return None;
            }
        }
        // Reach here means the long key is the super key of the sort one
        Some(long_key)
    }
pub fn try_merge_key ( key1 : & SortKey < ' a > , key2 : & SortKey < ' a > ) -> Option < SortKey < ' a > > { if key1 . is_empty ( ) || key2 . is_empty ( ) { panic ! ( " " ) ; } let key1 = key1 . clone ( ) ; let key2 = key2 . clone ( ) ; // Verify if time column in the sort key match key1 . columns . get_index_of ( TIME_COLUMN_NAME ) { None => panic ! ( " " key1 ) , Some ( idx ) => { if idx < key1 . len ( ) - 1 { panic ! ( " " key1 ) } } } match key2 . columns . get_index_of ( TIME_COLUMN_NAME ) { None => panic ! ( " " key2 ) , Some ( idx ) => { if idx < key2 . len ( ) - 1 { panic ! ( " " key2 ) } } } let ( long_key , short_key ) = if key1 . len ( ) > key2 . len ( ) { ( key1 , key2 ) } else { ( key2 , key1 ) } ; // Go over short key and check its right-order availability in the long key let mut prev_long_idx : Option < usize > = None ; for ( col , sort_options ) in & short_key . columns { if let Some ( long_idx ) = long_key . find_index ( col , sort_options ) { match prev_long_idx { None => prev_long_idx = Some ( long_idx ) , Some ( prev_idx ) => { if long_idx > prev_idx { // In the right order, update the current idx prev_long_idx = Some ( long_idx ) ; } else { // Not in the right order return None ; } } } } else { // Not found return None ; } } // Reach here means the long key is the super key of the sort one Some ( long_key ) }
Returns merge key of the 2 given keys if one covers the other.
Returns merge key of the 2 given keys if one covers the other .
key1
&SortKey<'a>
key2
&SortKey<'a>
key1
&SortKey<'a>
key2
&SortKey<'a>