это всё константы, их отбрасываем. как правило - вызов ф-ции - это считанные наносекунды
по алгоритмике у тебя хуже, по скорости, скорее всего, тоже, т.к. второй проход, скорее всего, будет дольше, чем вызов коллбека в рамках одной итерации
Вот в этом я не уверен, надо потестить. Сеасибо за идею
Расскажите волшебный алгоритм константного добавления во множество
ок
Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structures used in this Set objects specification is only intended to describe the required observable semantics of Set objects. It is not intended to be a viable implementation model.
Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structures used in this Set objects specification is only intended to describe the required observable semantics of Set objects. It is not intended to be a viable implementation model.
это из спецификации. сублинейное - это не только логарифмы, это всё, что быстрее O(n)