Data structure with O (1) performance for get (int index) and the ability to avoid duplication

Set is an obvious choice if I don't want to duplicate my data list.

However, it Setdoes not have a method get(int index): Why doesn't java.util.Set get (int index)?

A few suggestions for implementing pseudo get(int index)and none of them are effective.

  • toArray and access the new array by index.
  • Get an iterator and use a loop forto access the indexed item in the account.

Is there any advanced data structure that allows me

  • Avoid duplication.
  • Perform O (1) for get(int index).
+4
source share
2

- , HashSet ArrayList. add , . get .

- ? , - O (N). , - .

+9

BiMap<Integer, T>

( " " ) - , , . " ", , , , .

+3

Source: https://habr.com/ru/post/1545020/


All Articles