Resizing Vec
ResizingVec
is a data structure for when
- each data has a unique integer id
- the ids (numbers) are clustered
The underlying data structured looks as following:
Now when you insert an item with the index 5
.
let mut r_vec = new;
r_vec.insert;
println;
// Will print:
// ResizingVec { vec: [None, None, None, None, None, Some("5th elem")], active: 1 }
Since the element got inserted at the 5th index but prior to inserting no other elements existed the vector got filled with None
values for the indicies 0-4.
The time complexity of an insert operation is as an result depending on whether the vector has to resize or not.
Use cases
This can be used for data with unique integer ids and having to rely on fast read operations.
This can could be used for financial data for instance:
let mut id_assigner = new;
let mut r_vec = new;
let id = id_assigner.get;
r_vec.insert;
// Now that we have a unique id for every ticker we can use that to easily info about each ticker and enrich our price data quickly with it.
let price = Price ;
let full_name = r_vec;
printlnt!;
Another application is that some financial data providers do not send the ticker/option contract for every trade/nbbo but rather send you an id identifier.
So in the morning you get for every ticker a message such as:
ticker: AAPL, locate: 10, channel: 5
Each locate is unique per channel so you could create the following ResizingVec
:
let mut channel_five = new;
channel_five.insert;
Now when you get a trade execution:
channel: 5, locate: 10, size: 10, price: 120
then you can do:
let ticker = channel_five;
println!;