Commit 2c805c0a authored by saad.aswad's avatar saad.aswad

Implementing removeGroup function

parent ddfe305f
......@@ -6,9 +6,7 @@
<component name="ChangeListManager">
<list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Counters for contain and removing">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.MD" beforeDir="false" afterPath="$PROJECT_DIR$/README.MD" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/SortList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/SortList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/SyncListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/SyncListTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/RWLockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/RWLockList.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -25,7 +23,7 @@
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="task1" />
<entry key="$PROJECT_DIR$" value="master" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
......@@ -51,7 +49,7 @@
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "task2__3__4",
"git-widget-placeholder": "extraphase",
"kotlin-language-version-configured": "true",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
......
import java.util.Collection;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class RWLockList extends SortList {
......@@ -79,4 +80,35 @@ public class RWLockList extends SortList {
}
}
public int removeGroup(Collection<Integer> items) {
lock.writeLock().lock();
int internalSuccess = 0;
try {
for (Integer item : items) {
Entry prev = this.head;
Entry curr = prev.next;
while (curr.object.compareTo(item) < 0) {
prev = curr;
curr = prev.next;
}
if (curr.object.equals(item)) {
prev.next = curr.next;
this.length--;
internalSuccess++;
}
}
if (internalSuccess > 0) {
removeSuccess+=internalSuccess;
} else {
if (!items.isEmpty()) {
removeFailure+=items.size() - internalSuccess;
}
}
} finally {
lock.writeLock().unlock();
}
return internalSuccess;
}
}
......@@ -26,7 +26,7 @@ public class SyncListTest extends TestCase {
}
}
public void helper(SortList list, String label, int numThreads, int randLen) {
public void helper(SortList list, String label, int numThreads, int randLen) {
RandomSeq seq = new RandomSeq(0, 80_000);
List<Thread> addThreads = new ArrayList<>();
List<Thread> containThreads = new ArrayList<>();
......@@ -147,4 +147,8 @@ public class SyncListTest extends TestCase {
System.out.println("FINISHED benchmarking");
}
public void testRemoveGroup(){
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment