Я реализую вставку для Sortset SkipList. Все было в порядке, но теперь мне нужно заставить get(index) работать в O(logn). Это означает, что мне нужно объединить список пропуска Sortedset и список пропуска. Итак, как я могу обновить длину указателей, сохраняя при этом порядок элементов в наборе?
public boolean add(T x) {
Node u = sentinel;
int r = h;
int comp = 0;
int j = -1; // Track index position as we traverse
Node w = new Node(x, pickHeight());
// Traverse the levels from top down to find the correct position for `x`
while (r >= 0) {
while (u.next[r] != null && (comp = c.compare(u.next[r].x, x)) < 0) {
u = u.next[r];
}
// Increment length on level `r` to account for the new node
;
if (u.next[r] != null && comp == 0) return false; // Duplicate, exit early
stack[r--] = u; // Store the node `u` in the stack for each level
}
// Update height if the new node `w` requires it
while (h < w.height()) {
stack[++h] = sentinel;
sentinel.length[h] = n + 1;
}
j++; // `j` now represents the exact insertion index for `w`
// Insert `w` and update lengths at each level
for (int i = 0; i < w.next.length; i++) {
w.next = stack.next;
stack.next = w;
// Calculate the lengths for `w` and `stack`
}
n++; // Increment node count
return true;
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -insertion
Как мы можем обновить длину каждого указателя при вставке списка пропуска Sortedset? ⇐ JAVA
Программисты JAVA общаются здесь
1730002038
Anonymous
Я реализую вставку для Sortset SkipList. Все было в порядке, но теперь мне нужно заставить get(index) работать в O(logn). Это означает, что мне нужно объединить список пропуска Sortedset и список пропуска. Итак, как я могу обновить длину указателей, сохраняя при этом порядок элементов в наборе?
public boolean add(T x) {
Node u = sentinel;
int r = h;
int comp = 0;
int j = -1; // Track index position as we traverse
Node w = new Node(x, pickHeight());
// Traverse the levels from top down to find the correct position for `x`
while (r >= 0) {
while (u.next[r] != null && (comp = c.compare(u.next[r].x, x)) < 0) {
u = u.next[r];
}
// Increment length on level `r` to account for the new node
;
if (u.next[r] != null && comp == 0) return false; // Duplicate, exit early
stack[r--] = u; // Store the node `u` in the stack for each level
}
// Update height if the new node `w` requires it
while (h < w.height()) {
stack[++h] = sentinel;
sentinel.length[h] = n + 1;
}
j++; // `j` now represents the exact insertion index for `w`
// Insert `w` and update lengths at each level
for (int i = 0; i < w.next.length; i++) {
w.next[i] = stack[i].next[i];
stack[i].next[i] = w;
// Calculate the lengths for `w` and `stack[i]`
}
n++; // Increment node count
return true;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79129018/how-can-we-update-the-length-of-each-pointer-in-sortedset-skip-list-insertion[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия