Files
sml-projects/rust23_gap.txt

1 line
589 KiB
Plaintext
Raw Normal View History

'/// This is an implementation of a general purpose skip list. It was originallyn/// ported from a version of skiplists intended for efficient string handlingn/// found here - https://github.com/josephg/rustropenn/// This implementation is not optimized for strings (there's some stringn/// specific features like unicode handling which have been intentionallyn/// removed for simplicity). But it does have another somewhat unusual feature -n/// users can specify their own size function, and lookups, inserts and deletesn/// can use their custom length property to specify offsets.''nn/// Unlike other rust rope implementations, this implementation should be veryn/// fast; but it manages that through heavy use of unsafe pointers and C-stylen/// dynamic arrays.nnuse std::{mem, ptr}''use std::mem::MaybeUninit;nuse std::ptr::NonNull;nuse std::alloc::{alloc, dealloc, Layout};nuse std::cmp::min;nuse std::marker::PhantomData;nuse std::iter;nnuse std::fmt;nnuse rand::{RngCore, Rng, SeedableRng};nuse rand::rngs::SmallRng;nn/// The likelyhood a node will have height (n'2'+1) instead of nnconst BIAS: u8 = 100; // out of 256.nn/// The number of it''''t's'i'L'ems in each node. Must fit in a u8 thanks to Node.n#[cfg(debug_assertions)]nconst NODE_NUM_ITEMS: usize ='10''2''10''2'''0'1''''1''''2' 10;nn#[cfg(not(debug_assertions))]nconst NODE_NUM_ITEMS: usize = 100;nn/// Rope operations will move to linear time after NODE_STR_SIZE * 2 ^n/// MAX_HEIGHT length. (With a smaller constant the higher this is). On the flipn/// side, cursors grow linearly with this number; so smaller is marginallyn/// better when the''''m'e't'I''''V''''T''''I''''I''' conten''''m'e''''m'e't't'I'''t''s'' ''a''r''e sm'I'''aller.n#[cfg(debug_assertions)]nco'5''2'nst MAX_HEIGHT: usize = 5;'m'n'e'n't'#'I'[cf''g('V'not''('m'd'e'''t'T'ebu''g_'I'ass''ertions'I'))]''nconst MAX_H'm'E'e''I''''m'I't'e''G''t'I'H'I'T:''m'' u'e'''s't'i'''V'ze ='''' 10;''m'T'''n'e'nnc'''t'''on'm'''I'I'e''st'''t' M''''AX_HE'V'IGHT_U8: '''I'u8''T'''''''''''''''''I'I'''''''Par'''m'tia'e'lE''t'''''I'''m'I'q']'''m''e'E''''e''' 't'''t',''>'I'I'''''''')'''q'm'''''m'''p'e'u''m'V'e''t''''b(su'e't''pe'm'r''''''I't''e') ''T''''I''t'''''''i't'''r''V'''a'''I''P'('e'''''v'i'''r''T'e'd'''['#'n''' ''''= MAX_'''I'''''I'''impl<Item: ListItem> Default for ItemMarker<Item> {n fn default() -> Self { Self::null() }n}nn'''''I'''''''''''C''''''':':'t'm'f''''''g'u'b'e'D'l''on'''''''''''''''''''''''''''''':':'t'm'f''''''''''''t'm'f'''''':':'d'''':'t's''''''''''''''''''''' '''''''''''''''''''''';')'''r'e'k'r'a'M'm'e't'I'''('d'a'p'.'f' ''' }''n 'n ' '{' 't'l'u's'e'R' '>'-' ')'>''''''_'''<'r'e't't'a'm'r'o'F' 't'u'm'&' ':'f' ','f'l'e's'&'('t'm'f' 'n'f'''''''']''I''')'y'p''m'o'C' '''I''e''m'''m'' ','e't''e''''e''I'''C'''t''''''''l'p'm'i''''//! Utilities for formatting and pr'' /// An optimized method to calculate the userlen of a slice of ListItems.n /// The default implementation simply calls [`get_usersize`] in a loop.'' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''.'p'o'o''n ''''''''''''''''''''d'e's's'a'p'''''''''''''''''''''''''''''''''''''''''''.'t'e's'&''''f'f'o' 'd'e'i'f'i'c'e'p's' 'e'm''n '// ' fn split_item(self, _at: usize) -> (Self, Self) {'o's' '''''''''''''s' 'a'''''''''''''p's' 'a' 't'a' ''''''''''''''''''s'm'e't'i' 'f'o' 'r'i'a'p' 'a' 'o't'''''''a' 'n'i'''t'a' 'm'e't'i' 'd'e'm'a'n''''e'p's' 'e'h't' 't'i'l'p'S' '/'/'/' 'l' 'a' 'n'i' ']'`'e'z'i's'r'e's'u'_'t'e'g'`'[''''g' 's'l'l'a'c' 'y'l'p'm'i's' 'n'o'i't'a't'n'e'm'e'l'p'm'i' 't'l'u'a'f'e'd' 'e'h'T' '.'s'm'e't'I't's'i'L' 'f'o' 'e'c'i'l's' 'a' 'f'o' 'n'e'l'r'e's'u' 'e'h't' 'e't'a'l'u'c'l'a'c' 'o't' 'd'o'h't'e'm''''r'e'v' 'd'e'z'i'm'i't'p'o' 'n'A'''''''''g'n'e'l'''''r'e's'u' 'e'h'T' ''''''' '/'/'/'/''' '''''''''/'/'/' ''''''''''/'/'/'''n 'inting strings.nn#![stable(feature = 'rust1', since = '1.0.0')]nnuse crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};nuse crate::marker::PhantomData;nuse crate::mem;nuse crate::num::flt2dec;n