From ef4dfab3c29868bb1069a5251b153c26674f4841 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Thu, 7 Dec 2023 01:58:28 -0700 Subject: [PATCH] only insert 1 entry for each dataentry --- build.gradle | 2 +- .../nucleodb/library/database/index/TrieIndex.java | 12 ++++++++---- .../nucleodb/library/database/index/trie/Entry.java | 5 ++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 49ed64a..16e6a9b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'com.nucleodb' -version = '1.13.5' +version = '1.13.6' repositories { mavenCentral() diff --git a/src/main/java/com/nucleodb/library/database/index/TrieIndex.java b/src/main/java/com/nucleodb/library/database/index/TrieIndex.java index b72f79c..27624b9 100644 --- a/src/main/java/com/nucleodb/library/database/index/TrieIndex.java +++ b/src/main/java/com/nucleodb/library/database/index/TrieIndex.java @@ -45,9 +45,14 @@ Node getNodeFromIntBuffer(TreeMap treeMap, int character) { @Override public void add(T obj) throws JsonProcessingException { + String key = getKey(obj); + Entry entry = entries.get(key); + if(entry==null){ + entry = new Entry(obj); + } for (Object o : getIndexValue(obj)) { if(o instanceof String){ - insert(obj, (String) o); + insert(entry, (String) o); } } } @@ -126,7 +131,7 @@ public void delete(Entry entry){ } public void insert(T obj, String val) { - Entry entry = new Entry(obj, new Stack<>()); + Entry entry = new Entry(obj); insert(entry, val); } @@ -134,7 +139,6 @@ public void insert(Entry entry, String val) { String key = getKey((T)entry.getData()); PrimitiveIterator.OfInt iterator = val.chars().iterator(); Node tmp = this.root; - Stack nodePath = entry.getLastNodes(); while (iterator.hasNext()) { int character = iterator.next(); Node nodeTraversal = getNodeFromIntBuffer(tmp.getNodes(), character); @@ -148,7 +152,7 @@ public void insert(Entry entry, String val) { tmp = nodeTraversal; tmp.getPartialEntries().add(entry); } - nodePath.add(tmp); // add leaf + entry.getLastNodes().add(tmp); // add leaf entries.put(key, entry); tmp.getEntries().add(entry); } diff --git a/src/main/java/com/nucleodb/library/database/index/trie/Entry.java b/src/main/java/com/nucleodb/library/database/index/trie/Entry.java index 3c48eda..f64d410 100644 --- a/src/main/java/com/nucleodb/library/database/index/trie/Entry.java +++ b/src/main/java/com/nucleodb/library/database/index/trie/Entry.java @@ -7,11 +7,10 @@ public class Entry{ T data; - Stack lastNodes; + Stack lastNodes = new Stack<>(); - public Entry(T data, Stack nodes) { + public Entry(T data) { this.data = data; - this.lastNodes = nodes; } public T getData() {