Parcel Attribute Store with TTL
Problem statement
Process timestamped operations on parcels. Each parcel stores independently expiring named string attributes, and each operation is a string array.
["SET", timestamp, parcel, name, value, ttl]overwrites the attribute and returns"OK". A TTL of zero never expires.["GET", timestamp, parcel, name]returns the live value or an empty string.["UPDATE_IF_MATCH", timestamp, parcel, name, expected, value, ttl]updates a live attribute only when its current value equalsexpected; it returns"true"on success and"false"otherwise.["LIST", timestamp, parcel]returns live attributes asname(value), sorted by name and joined with", ".["LIST_PREFIX", timestamp, parcel, prefix]returns the same listing restricted to names that start withprefix.
A positive-TTL attribute set at time t is absent at every operation timestamp greater than or equal to t + ttl. Return one string per operation in input order.
Function
processParcelAttributes(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","1","p1","color","red","5"],["SET","2","p1","carrier","air","0"],["LIST","3","p1"],["GET","6","p1","color"],["LIST_PREFIX","6","p1","car"]]return = ["OK","OK","carrier(air), color(red)","","carrier(air)"]The color expires exactly at time six while the zero-TTL carrier remains.
Example 2
operations = [["SET","4","p","zone","west","0"],["UPDATE_IF_MATCH","5","p","zone","east","north","0"],["UPDATE_IF_MATCH","6","p","zone","west","north","3"],["GET","9","p","zone"]]return = ["OK","false","true",""]Only the matching update succeeds, and its replacement expires at time nine.
Constraints
1 <= operations.length <= 100000- Timestamps are nondecreasing integers between
0and1000000000. - Parcel IDs, attribute names, prefixes, and values contain at most
80visible ASCII characters; names contain no parentheses or commas. 0 <= ttl <= 1000000000.