I need a queue $[x_0, ..., x_n]$ that supports the following operations:
- $\operatorname{enqueue}([x_0, ..., x_n], x) = [x_0, ..., x_n, x]$
- $\operatorname{dequeue}([x_0, ..., x_n]) = [x_1, ..., x_n]$
- $\operatorname{lookup}([x_0, ..., x_n], i) = x_i$
- $\operatorname{update}([x_0, ..., x_n], i, y) = [x_0, ..., x_{i - 1}, y, x_{i + 1}, ... x_n]$
- $\operatorname{insert}([x_0, ..., x_n], i, y) = [x_0, ..., x_i, y, x_{i + 1}, ..., x_n]$
- $\operatorname{delete}([x_0, ..., x_n], i) = [x_0, ..., x_{i - 1}, x_{i + 1}, ... x_n]$
- $\operatorname{length}([x_0, ..., x_n]) = n + 1$
All operations should be in $O(\log n)$. The data structure should be atomic and persistent, i.e. it is written to a random-access data storage device, such a hard disk or flash memory. Therefore the data structure should minimize the number of seeks. I thought about using Counted B-Trees without keys and with a rollback journal. I also looked at several purely real-time functional data structures that use multiple lists (lists can be efficiently implemented with a file system with a truncate operation) but they seemed to be too complicated or not randomly accessible.
Assume that the filesystem has the following operations:
- write(file, offset, x)
- read(file, offset, length)
- append(file, x)
- truncate(file, length)
Is there any other data structure that I is more efficient or easier to implement while being as efficient?