Commit d3fa7a5b authored by saad.aswad's avatar saad.aswad

List length, sorting in Adding implementations.

parent ce0771ef
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Concurrent Sorted Linked List Implementations"> <list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Concurrent Sorted Linked List Implementations">
<change afterPath="$PROJECT_DIR$/src/test/java/AddThread.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/ContainThread.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/RandomSeq.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/RemoveThread.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/TestThread.java" afterDir="false" />
<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/LockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/LockList.java" 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/main/java/SyncList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/SyncList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/AddThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/AddThread.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/ContainThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ContainThread.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/RemoveThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/RemoveThread.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/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" />
...@@ -27,11 +28,19 @@ ...@@ -27,11 +28,19 @@
</option> </option>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="master" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 2
}]]></component>
<component name="ProjectId" id="2NMPKhBDgdyw9qxmyQBX74HdmhD" /> <component name="ProjectId" id="2NMPKhBDgdyw9qxmyQBX74HdmhD" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" /> <ConfirmationsSetting value="2" id="Add" />
...@@ -40,17 +49,20 @@ ...@@ -40,17 +49,20 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "JUnit.SyncListTest.testRun.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;project.structure.proportion&quot;: &quot;0.0&quot;, "git-widget-placeholder": "task1",
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot; "kotlin-language-version-configured": "true",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0"
} }
}</component> }]]></component>
<component name="RunManager" selected="JUnit.SyncListTest.testRun"> <component name="RunManager" selected="JUnit.SyncListTest.testRun">
<configuration name="SyncListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="SyncListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="SortLinkedList" /> <module name="SortLinkedList" />
......
...@@ -25,6 +25,7 @@ public class LockList extends SortList { ...@@ -25,6 +25,7 @@ public class LockList extends SortList {
Entry newEntry = new Entry(obj); Entry newEntry = new Entry(obj);
newEntry.next = curr; newEntry.next = curr;
prev.next = newEntry; prev.next = newEntry;
this.length++;
return true; return true;
} }
} finally { } finally {
...@@ -44,6 +45,7 @@ public class LockList extends SortList { ...@@ -44,6 +45,7 @@ public class LockList extends SortList {
} }
if (curr.object.equals(obj)) { if (curr.object.equals(obj)) {
prev.next = curr.next; prev.next = curr.next;
this.length--;
return true; return true;
} else { } else {
return false; return false;
......
...@@ -24,6 +24,7 @@ public class RWLockList extends SortList { ...@@ -24,6 +24,7 @@ public class RWLockList extends SortList {
Entry newEntry = new Entry(obj); Entry newEntry = new Entry(obj);
newEntry.next = curr; newEntry.next = curr;
prev.next = newEntry; prev.next = newEntry;
this.length++;
return true; return true;
} }
} finally { } finally {
...@@ -43,6 +44,7 @@ public class RWLockList extends SortList { ...@@ -43,6 +44,7 @@ public class RWLockList extends SortList {
} }
if (curr.object.equals(obj)) { if (curr.object.equals(obj)) {
prev.next = curr.next; prev.next = curr.next;
this.length--;
return true; return true;
} else { } else {
return false; return false;
......
public abstract class SortList { public abstract class SortList {
public Entry head; public Entry head;
public long length;
public SortList() { public SortList() {
this.head = new Entry(Integer.MIN_VALUE); this.head = new Entry(Integer.MIN_VALUE);
this.head.next =new Entry(Integer.MAX_VALUE); this.head.next =new Entry(Integer.MAX_VALUE);
this.length = 2;
} }
public abstract boolean add(Integer obj); public abstract boolean add(Integer obj);
......
...@@ -18,6 +18,7 @@ public class SyncList extends SortList { ...@@ -18,6 +18,7 @@ public class SyncList extends SortList {
Entry newEntry = new Entry(obj); Entry newEntry = new Entry(obj);
newEntry.next = curr; newEntry.next = curr;
prev.next = newEntry; prev.next = newEntry;
this.length++;
return true; return true;
} }
} }
...@@ -32,6 +33,7 @@ public class SyncList extends SortList { ...@@ -32,6 +33,7 @@ public class SyncList extends SortList {
} }
if (curr.object.equals(obj)) { if (curr.object.equals(obj)) {
prev.next = curr.next; prev.next = curr.next;
this.length--;
return true; return true;
} else { } else {
return false; return false;
......
...@@ -5,8 +5,8 @@ public class AddThread extends TestThread implements Runnable { ...@@ -5,8 +5,8 @@ public class AddThread extends TestThread implements Runnable {
@Override @Override
public void run() { public void run() {
for (int i = 0; i < nums.length; i++) { for (Integer num : nums) {
list.add(nums[i]); list.add(num);
} }
} }
} }
...@@ -5,8 +5,8 @@ public class ContainThread extends TestThread implements Runnable{ ...@@ -5,8 +5,8 @@ public class ContainThread extends TestThread implements Runnable{
@Override @Override
public void run() { public void run() {
for (int i = 0; i < nums.length; i++) { for (Integer num : nums) {
list.contain(nums[i]); list.contain(num);
} }
} }
} }
...@@ -5,8 +5,8 @@ public class RemoveThread extends TestThread implements Runnable{ ...@@ -5,8 +5,8 @@ public class RemoveThread extends TestThread implements Runnable{
@Override @Override
public void run() { public void run() {
for (int i = 0; i < nums.length; i++) { for (Integer num : nums) {
list.remove(nums[i]); list.remove(num);
} }
} }
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ public class SyncListTest extends TestCase { ...@@ -27,7 +27,7 @@ public class SyncListTest extends TestCase {
} }
int randLen = 20_000; int randLen = 20_000;
public void testHelp(SortList list, String label) { public void helper(SortList list, String label) {
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<>();
...@@ -58,6 +58,11 @@ public class SyncListTest extends TestCase { ...@@ -58,6 +58,11 @@ public class SyncListTest extends TestCase {
System.out.println("ADD "+label+" execution task: "+endA+" ms"); System.out.println("ADD "+label+" execution task: "+endA+" ms");
long listLengthAfterAdds = list.length;
System.out.println("Length of the list after adding: "+listLengthAfterAdds);
long startC = System.currentTimeMillis(); long startC = System.currentTimeMillis();
containThreads.stream().forEach(e -> e.start() ); containThreads.stream().forEach(e -> e.start() );
...@@ -89,12 +94,12 @@ public class SyncListTest extends TestCase { ...@@ -89,12 +94,12 @@ public class SyncListTest extends TestCase {
public void testRun(){ public void testRun(){
SyncList syncList = new SyncList(); SyncList syncList = new SyncList();
testHelp(syncList,"Synchronization"); helper(syncList,"Synchronization");
System.out.println("=============="); System.out.println("=======================================");
RWLockList rwLockList = new RWLockList(); RWLockList rwLockList = new RWLockList();
testHelp(rwLockList, "RWLock"); helper(rwLockList, "RWLock");
System.out.println("=============="); System.out.println("=======================================");
LockList list = new LockList(); LockList list = new LockList();
testHelp(list,"Lock"); helper(list,"Lock");
} }
} }
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