forked from polis-vk/2023-nosql-lsm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
4,366 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
version: "2" | ||
plugins: | ||
duplication: | ||
enabled: false | ||
config: | ||
languages: | ||
java: | ||
checkstyle: | ||
enabled: true | ||
config: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: autoupdate | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
autoupdate: | ||
name: autoupdate | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: docker://chinthakagodawita/autoupdate-action:v1 | ||
env: | ||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | ||
- run: echo 'Merge conflicts found!' | ||
if: ${{ steps.autoupdate.outputs.conflicted }} | ||
- run: echo 'No merge conflicts' | ||
if: ${{ !steps.autoupdate.outputs.conflicted }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ru.vk.itmo.abramovilya; | ||
|
||
import ru.vk.itmo.Dao; | ||
import ru.vk.itmo.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.util.Iterator; | ||
import java.util.concurrent.ConcurrentNavigableMap; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
public class InMemoryDao implements Dao<MemorySegment, Entry<MemorySegment>> { | ||
private final ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>> map = | ||
new ConcurrentSkipListMap<>(InMemoryDao::compareMemorySegments); | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to) { | ||
ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>> subMap; | ||
if (from == null && to == null) { | ||
subMap = map; | ||
} else if (from == null) { | ||
subMap = map.headMap(to); | ||
} else if (to == null) { | ||
subMap = map.tailMap(from); | ||
} else { | ||
subMap = map.subMap(from, to); | ||
} | ||
return subMap.values().iterator(); | ||
} | ||
|
||
@Override | ||
public void upsert(Entry<MemorySegment> entry) { | ||
map.put(entry.key(), entry); | ||
} | ||
|
||
@Override | ||
public Entry<MemorySegment> get(MemorySegment key) { | ||
return map.get(key); | ||
} | ||
|
||
private static int compareMemorySegments(MemorySegment segment1, MemorySegment segment2) { | ||
long offset = segment1.mismatch(segment2); | ||
if (offset == -1) { | ||
return 0; | ||
} else if (offset == segment1.byteSize()) { | ||
return -1; | ||
} else if (offset == segment2.byteSize()) { | ||
return 1; | ||
} | ||
return Byte.compare( | ||
segment1.get(ValueLayout.JAVA_BYTE, offset), | ||
segment2.get(ValueLayout.JAVA_BYTE, offset) | ||
); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/ru/vk/itmo/bazhenovkirill/InMemoryDaoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ru.vk.itmo.bazhenovkirill; | ||
|
||
import ru.vk.itmo.Dao; | ||
import ru.vk.itmo.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.util.Iterator; | ||
import java.util.concurrent.ConcurrentNavigableMap; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
public class InMemoryDaoImpl implements Dao<MemorySegment, Entry<MemorySegment>> { | ||
|
||
private final ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>> storage = new ConcurrentSkipListMap<>( | ||
(ms1, ms2) -> { | ||
long mismatch = ms1.mismatch(ms2); | ||
if (mismatch == -1) { | ||
return 0; | ||
} | ||
if (ms2.byteSize() == mismatch) { | ||
return 1; | ||
} | ||
if (ms1.byteSize() == mismatch) { | ||
return -1; | ||
} | ||
return Byte.compare( | ||
ms1.get(ValueLayout.JAVA_BYTE, mismatch), | ||
ms2.get(ValueLayout.JAVA_BYTE, mismatch)); | ||
} | ||
); | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to) { | ||
if (from == null) { | ||
if (to != null) { | ||
return storage.headMap(to).values().iterator(); | ||
} | ||
return storage.values().iterator(); | ||
} | ||
if (to == null) { | ||
return storage.tailMap(from).values().iterator(); | ||
} | ||
return storage.subMap(from, true, to, false).values().iterator(); | ||
} | ||
|
||
@Override | ||
public Entry<MemorySegment> get(MemorySegment key) { | ||
return storage.get(key); | ||
} | ||
|
||
@Override | ||
public void upsert(Entry<MemorySegment> entry) { | ||
storage.put(entry.key(), entry); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/ru/vk/itmo/belonogovnikolay/InMemoryTreeDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ru.vk.itmo.belonogovnikolay; | ||
|
||
import ru.vk.itmo.Dao; | ||
import ru.vk.itmo.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.util.Iterator; | ||
import java.util.NavigableMap; | ||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
public final class InMemoryTreeDao implements Dao<MemorySegment, Entry<MemorySegment>> { | ||
|
||
private final NavigableMap<MemorySegment, Entry<MemorySegment>> arena; | ||
|
||
private InMemoryTreeDao() { | ||
this.arena = new ConcurrentSkipListMap<>(new MemorySegmentComparator()); | ||
} | ||
|
||
public static Dao<MemorySegment, Entry<MemorySegment>> newInstance() { | ||
return new InMemoryTreeDao(); | ||
} | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> allFrom(MemorySegment from) { | ||
return this.arena.tailMap(from).values().iterator(); | ||
} | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> allTo(MemorySegment to) { | ||
return this.arena.headMap(to).values().iterator(); | ||
} | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> get(MemorySegment from, MemorySegment to) { | ||
if (Objects.isNull(from) && Objects.isNull(to)) { | ||
return this.arena.values().iterator(); | ||
} else if (Objects.isNull(from)) { | ||
return allTo(to); | ||
} else if (Objects.isNull(to)) { | ||
return allFrom(from); | ||
} | ||
|
||
return this.arena.subMap(from, to).values().iterator(); | ||
} | ||
|
||
@Override | ||
public Entry<MemorySegment> get(MemorySegment key) { | ||
return this.arena.get(key); | ||
} | ||
|
||
@Override | ||
public void upsert(Entry<MemorySegment> entry) { | ||
if (Objects.isNull(entry)) { | ||
return; | ||
} | ||
|
||
this.arena.put(entry.key(), entry); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/ru/vk/itmo/belonogovnikolay/MemorySegmentComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ru.vk.itmo.belonogovnikolay; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.util.Comparator; | ||
|
||
public class MemorySegmentComparator implements Comparator<MemorySegment> { | ||
|
||
@Override | ||
public int compare(MemorySegment prevSegment, MemorySegment nextSegment) { | ||
|
||
long offset = prevSegment.mismatch(nextSegment); | ||
|
||
if (offset == nextSegment.byteSize()) { | ||
return 1; | ||
} else if (offset == prevSegment.byteSize()) { | ||
return -1; | ||
} else if (offset == -1) { | ||
return 0; | ||
} | ||
|
||
return Byte.compare(prevSegment.get(ValueLayout.JAVA_BYTE, offset), | ||
nextSegment.get(ValueLayout.JAVA_BYTE, offset)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/ru/vk/itmo/boturkhonovkamron/InMemoryDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ru.vk.itmo.boturkhonovkamron; | ||
|
||
import ru.vk.itmo.Dao; | ||
import ru.vk.itmo.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.util.Iterator; | ||
import java.util.concurrent.ConcurrentNavigableMap; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
/** | ||
* Реализация интерфейса Dao для работы с объектами типа MemorySegment в памяти. | ||
* | ||
* @author Kamron Boturkhonov | ||
* @since 2023.09.26 | ||
*/ | ||
public class InMemoryDao implements Dao<MemorySegment, Entry<MemorySegment>> { | ||
|
||
final ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>> data; | ||
|
||
public InMemoryDao() { | ||
data = new ConcurrentSkipListMap<>(new MemorySegmentComparator()); | ||
} | ||
|
||
@Override | ||
public Entry<MemorySegment> get(final MemorySegment key) { | ||
return data.get(key); | ||
} | ||
|
||
@Override | ||
public Iterator<Entry<MemorySegment>> get(final MemorySegment from, final MemorySegment to) { | ||
final ConcurrentNavigableMap<MemorySegment, Entry<MemorySegment>> subMap; | ||
if (from == null && to == null) { | ||
subMap = data; | ||
} else if (from == null) { | ||
subMap = data.headMap(to, false); | ||
} else if (to == null) { | ||
subMap = data.tailMap(from, true); | ||
} else { | ||
subMap = data.subMap(from, to); | ||
} | ||
return subMap.values().iterator(); | ||
} | ||
|
||
@Override | ||
public void upsert(final Entry<MemorySegment> entry) { | ||
data.merge(entry.key(), entry, (oldValue, newValue) -> newValue); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/ru/vk/itmo/boturkhonovkamron/MemorySegmentComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ru.vk.itmo.boturkhonovkamron; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.util.Comparator; | ||
|
||
/** | ||
* Реализация компаратора для сравнения объектов типа MemorySegment. | ||
* | ||
* @author Kamron Boturkhonov | ||
* @since 2023.09.27 | ||
*/ | ||
public class MemorySegmentComparator implements Comparator<MemorySegment> { | ||
|
||
@Override | ||
public int compare(final MemorySegment left, final MemorySegment right) { | ||
if (left == null || right == null) { | ||
return left == null ? -1 : 1; | ||
} | ||
if (left.equals(right)) { | ||
return 0; | ||
} | ||
final long leftSize = left.byteSize(); | ||
final long rightSize = right.byteSize(); | ||
final long mismatch = left.mismatch(right); | ||
if (mismatch >= 0 && leftSize != mismatch && rightSize != mismatch) { | ||
return Byte.compare(left.get(ValueLayout.JAVA_BYTE, mismatch), | ||
right.get(ValueLayout.JAVA_BYTE, mismatch)); | ||
} | ||
return Long.compare(leftSize, rightSize); | ||
} | ||
} |
Oops, something went wrong.