Skip to content

Use scala.collection.immutable.Queue for FIFOQueue instead of List#3

Merged
buster84 merged 1 commit into
Shanon:masterfrom
okumin:fix-data-structure
Sep 29, 2014
Merged

Use scala.collection.immutable.Queue for FIFOQueue instead of List#3
buster84 merged 1 commit into
Shanon:masterfrom
okumin:fix-data-structure

Conversation

@okumin

@okumin okumin commented Sep 13, 2014

Copy link
Copy Markdown

scala.collection.immutable.List is a singly linked list, so it is not efficient(O(n)) to append elements.
Using scala.collection.immutable.Queue, enqueue will be faster.

@okumin

okumin commented Sep 13, 2014

Copy link
Copy Markdown
Author

This FIFOQueue requires O(n) time for contains, deleteById and deleteByGroup.
If these operations is called many times, another data structure should be chosen (e.g. use two LinkedHashMaps whose keys are Task ID and group).

@buster84

Copy link
Copy Markdown

Thank you for your contribution!!!!
deleteById and deleteByGroup are not called many times but it depends on applications. contains is called as many times as enqueue so we need another data structure as you mentioned. Could you fix it?
BTW, this link is very useful: http://docs.scala-lang.org/overviews/collections/performance-characteristics.html

@okumin

okumin commented Sep 16, 2014

Copy link
Copy Markdown
Author

Thanks to your response.
There is a thing that I want to confirm.
CustomQueue seems not to be assigined tasks that have the same id, and then I can work on condition that this is constraint on CustomQueue, right?

@buster84

Copy link
Copy Markdown

Now, there is the constraint on any CustomQueue. But I am considering that the constraint should be depends on applications. So I am going to add CustomQueue trait isAddable method which check whether given task can be enqueued or not.

And I think FIFOQueue should have the constraint because it may be used as exclusive control in most cases, and actually we are using the constraint as exclusive control.

@buster84

Copy link
Copy Markdown

I forgot to say.. It is a good question!!

scala.collection.immutable.List is a singly linked list, so it is not efficient(O(n)) to append elements.
Using scala.collection.immutable.Queue, enqueue will be faster.
@okumin

okumin commented Sep 23, 2014

Copy link
Copy Markdown
Author

Updated branch.

But I am considering that the constraint should be depends on applications.

I agree this point, so I didn't change any interfaces and improve perfomance only.

buster84 pushed a commit that referenced this pull request Sep 29, 2014
Use scala.collection.immutable.Queue for FIFOQueue instead of List
@buster84 buster84 merged commit cf1ef9f into Shanon:master Sep 29, 2014
@buster84

Copy link
Copy Markdown

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants