-
Notifications
You must be signed in to change notification settings - Fork 543
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
[Compatibility] Added BZMPOP, BZPOPMAX and BZPOPMIN commands #884
base: main
Are you sure you want to change the base?
Changes from all commits
e506044
15d1b18
900a8cd
e65a3bd
c162ed4
4a0e996
85008cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,12 @@ public CollectionItemResult(byte[] key, byte[][] items) | |
Items = items; | ||
} | ||
|
||
public CollectionItemResult(byte[] key, (double Score, byte[] Element)[] scoredItems) | ||
{ | ||
Key = key; | ||
ScoredItems = scoredItems; | ||
} | ||
|
||
/// <summary> | ||
/// True if item was found | ||
/// </summary> | ||
|
@@ -40,6 +46,11 @@ public CollectionItemResult(byte[] key, byte[][] items) | |
/// </summary> | ||
internal byte[][] Items { get; } | ||
|
||
/// <summary> | ||
/// Scored items retrieved from collection, where each item has an associated score. | ||
/// </summary> | ||
internal (double Score, byte[] Element)[] ScoredItems { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of doing this we should re-use the Item & Items properties to store the elements & have matching double Score and double[] Scores properties. |
||
|
||
/// <summary> | ||
/// Instance of empty result | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Runtime.Intrinsics.X86; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mistake? |
||
using System.Text; | ||
using Garnet.common; | ||
using Tsavorite.core; | ||
|
@@ -886,6 +887,19 @@ private void SortedSetRank(ref ObjectInput input, ref SpanByteAndMemory output, | |
} | ||
} | ||
|
||
public (double Score, byte[] Element) Pop(bool popMaxScoreElement = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an XML comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should rename this to PopMinOrMax for clarity |
||
{ | ||
if (sortedSet.Count == 0) | ||
return default; | ||
|
||
var element = popMaxScoreElement ? sortedSet.Max : sortedSet.Min; | ||
sortedSet.Remove(element); | ||
sortedSetDict.Remove(element.Element); | ||
this.UpdateSize(element.Element, false); | ||
|
||
return element; | ||
} | ||
|
||
/// <summary> | ||
/// Removes and returns up to COUNT members with the low or high score | ||
/// </summary> | ||
|
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.
I would like to create a separate PR in future to remove
CollectionItemResult
class and replace it withSpanByteAndMemory
, Let me know if there is any issue with thatThere 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.
Why? It'd make the code less readable. I'd leave it as-is.