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

List length, sorting in Adding implementations.

parent ce0771ef
......@@ -5,13 +5,14 @@
</component>
<component name="ChangeListManager">
<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$/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" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -27,11 +28,19 @@
</option>
</component>
<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$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 2
}]]></component>
<component name="ProjectId" id="2NMPKhBDgdyw9qxmyQBX74HdmhD" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
......@@ -40,17 +49,20 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"JUnit.SyncListTest.testRun.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "task1",
"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">
<configuration name="SyncListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="SortLinkedList" />
......
......@@ -25,6 +25,7 @@ public class LockList extends SortList {
Entry newEntry = new Entry(obj);
newEntry.next = curr;
prev.next = newEntry;
this.length++;
return true;
}
} finally {
......@@ -44,6 +45,7 @@ public class LockList extends SortList {
}
if (curr.object.equals(obj)) {
prev.next = curr.next;
this.length--;
return true;
} else {
return false;
......
......@@ -24,6 +24,7 @@ public class RWLockList extends SortList {
Entry newEntry = new Entry(obj);
newEntry.next = curr;
prev.next = newEntry;
this.length++;
return true;
}
} finally {
......@@ -43,6 +44,7 @@ public class RWLockList extends SortList {
}
if (curr.object.equals(obj)) {
prev.next = curr.next;
this.length--;
return true;
} else {
return false;
......
public abstract class SortList {
public Entry head;
public long length;
public SortList() {
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);
......
......@@ -18,6 +18,7 @@ public class SyncList extends SortList {
Entry newEntry = new Entry(obj);
newEntry.next = curr;
prev.next = newEntry;
this.length++;
return true;
}
}
......@@ -32,6 +33,7 @@ public class SyncList extends SortList {
}
if (curr.object.equals(obj)) {
prev.next = curr.next;
this.length--;
return true;
} else {
return false;
......
......@@ -5,8 +5,8 @@ public class AddThread extends TestThread implements Runnable {
@Override
public void run() {
for (int i = 0; i < nums.length; i++) {
list.add(nums[i]);
for (Integer num : nums) {
list.add(num);
}
}
}
......@@ -5,8 +5,8 @@ public class ContainThread extends TestThread implements Runnable{
@Override
public void run() {
for (int i = 0; i < nums.length; i++) {
list.contain(nums[i]);
for (Integer num : nums) {
list.contain(num);
}
}
}
......@@ -5,8 +5,8 @@ public class RemoveThread extends TestThread implements Runnable{
@Override
public void run() {
for (int i = 0; i < nums.length; i++) {
list.remove(nums[i]);
for (Integer num : nums) {
list.remove(num);
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ public class SyncListTest extends TestCase {
}
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);
List<Thread> addThreads = new ArrayList<>();
List<Thread> containThreads = new ArrayList<>();
......@@ -58,6 +58,11 @@ public class SyncListTest extends TestCase {
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();
containThreads.stream().forEach(e -> e.start() );
......@@ -89,12 +94,12 @@ public class SyncListTest extends TestCase {
public void testRun(){
SyncList syncList = new SyncList();
testHelp(syncList,"Synchronization");
System.out.println("==============");
helper(syncList,"Synchronization");
System.out.println("=======================================");
RWLockList rwLockList = new RWLockList();
testHelp(rwLockList, "RWLock");
System.out.println("==============");
helper(rwLockList, "RWLock");
System.out.println("=======================================");
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