When you check this question, you find that add
and contains
is already O(1). So there is not much to improve there.
And I think that those two would be the only once could benefit from this constraint:
- "adding" becomes easier because you could simply remember the last value that was added; so only need one check when a new value is coming in
- similarly, when asking for "contained"; you have a first pre-check that tells you instantly when a given value can not be in the set
But that is about it.
And beyond that: when your constraint is really that each "new" entry that is about to be added is larger than the last one - then you don't need a Set in the first place. Because your constraint guarantees that all items will be unique. So in that sense, you could be looking into Lists, too ...
Regarding the comment that the question is asking between possible deltas between O(1) and O(1.5); my response:
The difference between O(1) and O(n) is of theoretical nature, you answer that using a pen and piece of paper. The difference between O(1.0) and O(1.005) ... there I would start with experiments and benchmarks.
Meaning: these "real" factors depend on various elements which are "close" to the underlying implementation. You would start by looking into how the Set that you are currently using is implemented for your platform; and how the JVM on your platform is doing its just-in-time-compiling. From there on, you could draw conclusions about things that could be improved by taking this constraint into consideration.
Finally; regarding the constraint degrading existing implementations. I guess this could also happen; as said above: such details really depend on the specific implementation. And beyond that: you named three different operations; and actual results can be very much different; depending on the operation type.
If I had to work on this problem; I would start by doing creating reasonably large files with "test data" (random numbers, increasing-only numbers; and variations of that). And then I would use a real profiler (or at least sophisticated benchmarking) and start measuring.