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

Implementing removeGroup function

parent ddfe305f
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Counters for contain and removing"> <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$/.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/RWLockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/RWLockList.java" 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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -25,7 +23,7 @@ ...@@ -25,7 +23,7 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="task1" /> <entry key="$PROJECT_DIR$" value="master" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
...@@ -51,7 +49,7 @@ ...@@ -51,7 +49,7 @@
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true", "SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "task2__3__4", "git-widget-placeholder": "extraphase",
"kotlin-language-version-configured": "true", "kotlin-language-version-configured": "true",
"project.structure.last.edited": "Modules", "project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0", "project.structure.proportion": "0.0",
......
import java.util.Collection;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
public class RWLockList extends SortList { public class RWLockList extends SortList {
...@@ -79,4 +80,35 @@ 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 { ...@@ -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); RandomSeq seq = new RandomSeq(0, 80_000);
List<Thread> addThreads = new ArrayList<>(); List<Thread> addThreads = new ArrayList<>();
List<Thread> containThreads = new ArrayList<>(); List<Thread> containThreads = new ArrayList<>();
...@@ -147,4 +147,8 @@ public class SyncListTest extends TestCase { ...@@ -147,4 +147,8 @@ public class SyncListTest extends TestCase {
System.out.println("FINISHED benchmarking"); 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