-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queue #7064
Queue #7064
Conversation
acee7b2
to
6e0683e
Compare
I've gone back and forth on this in my head, but I think that this approach is probably the best, as opposed to new variable types. It's a bit of a departure for people (me) used to lists and how they look in skript, but considering how other languages approach data structures it makes a lot more sense for us to just have one variable type and multiple structures that can go inside them, with common syntaxes to access them. I would eventually like to see us rework the list syntax into a more generic structure (perhaps {list::index} could access maps, arrays, or queues: I'll do a code review shortly, just wanted to share my high level thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks solid, though i'd like more tests for invalid behavior like nulls, and docs for the queue classinfo
src/main/java/ch/njol/skript/expressions/ExprDequeuedQueue.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprDequeuedQueue.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what I found. As for whether this should be implemented, I think it is worth consideration.
Also, does this support size of {queue}
?
src/main/java/ch/njol/skript/expressions/ExprDequeuedQueue.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprQueueStartEnd.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few other things. This is shaping up nicely
src/main/java/ch/njol/skript/expressions/ExprDequeuedQueue.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprQueueStartEnd.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprQueueStartEnd.java
Outdated
Show resolved
Hide resolved
public boolean init(Expression<?>[] expressions, int pattern, Kleenean delayed, ParseResult result) { | ||
if (!this.getParser().hasExperiment(Feature.QUEUES)) | ||
return false; | ||
if (result.hasTag("contents")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump (this can be replaced with an expressions[0] != null
check
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com> Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
Description
Please note: this is just one of a number of experiments, it may never see the light of day.
We were poking around with some collection ideas.
I thought about a queue, because it's annoying to make with list variables.
Removing an element leaves its index open, meaning the next addition to the list will fill the empty spot, so you'd have to re-set the list each time you change an element.
The queue is a First In, First* Out collection. That means you take items out from the start, and add them to the end.
It's a regular type rather than a variable, and you don't have direct access to its indices in terms of setting and getting as you might with a Skript list.
Queues are super fast for adding to and removing from, but less efficient for random access.
These queues don't support empty (null) values either, so adding something that doesn't exist will have no effect. A queue should never contain an empty (null) value either, which means that if you ask for a value and you get nothing, the queue must be empty.
Creating a queue
Adding to a queue
It's also possible to add specifically to the start (or the end) of a queue.
Reading a queue
This uses
ExprElement
, but popping a queue removes the element you ask for.You can also "peek" at the starting and ending values of a queue.
Dequeueing
Queues can be converted to/from list variables easily.
Neither of these deletes or affects the other, it just rolls/unrolls the values.
Checking whether a queue is empty
This has compatibility with the
is empty
condition.Asking for an element of the queue will also return nothing if it is empty.
Indices & Setting
You cannot (currently) get the indices of an element, set an element at an index, or check whether a queue contains something.
This is not designed to be an equivalent/replacement list type, and these operations are all fairly inefficient for linked collections so I didn't want to encourage their (mis)use. You can, of course, still swap between queue -> list -> queue and do them all that way (at your own peril!)
Notes
The intentions around it were to make some odd bits and pieces easier, such as:
It'll definitely be a lot easier/more efficient than list variables for some things, but I also don't want this to be abused as a list-replacement so I'll have to consider whether it's a safe feature to add.
Target Minecraft Versions: any
Requirements: none
Related Issues: #371