MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / streamIteratorStart

Function streamIteratorStart

src/t_stream.cpp:1045–1085  ·  view source on GitHub ↗

Initialize the stream iterator, so that we can call iterating functions * to get the next items. This requires a corresponding streamIteratorStop() * at the end. The 'rev' parameter controls the direction. If it's zero the * iteration is from the start to the end element (inclusive), otherwise * if rev is non-zero, the iteration is reversed. * * Once the iterator is initialized, we iterate l

Source from the content-addressed store, hash-verified

1043 * }
1044 * streamIteratorStop(&myiterator); */
1045void streamIteratorStart(streamIterator *si, stream *s, streamID *start, streamID *end, int rev) {
1046 /* Initialize the iterator and translates the iteration start/stop
1047 * elements into a 128 big big-endian number. */
1048 if (start) {
1049 streamEncodeID(si->start_key,start);
1050 } else {
1051 si->start_key[0] = 0;
1052 si->start_key[1] = 0;
1053 }
1054
1055 if (end) {
1056 streamEncodeID(si->end_key,end);
1057 } else {
1058 si->end_key[0] = UINT64_MAX;
1059 si->end_key[1] = UINT64_MAX;
1060 }
1061
1062 /* Seek the correct node in the radix tree. */
1063 raxStart(&si->ri,s->rax);
1064 if (!rev) {
1065 if (start && (start->ms || start->seq)) {
1066 raxSeek(&si->ri,"<=",(unsigned char*)si->start_key,
1067 sizeof(si->start_key));
1068 if (raxEOF(&si->ri)) raxSeek(&si->ri,"^",NULL,0);
1069 } else {
1070 raxSeek(&si->ri,"^",NULL,0);
1071 }
1072 } else {
1073 if (end && (end->ms || end->seq)) {
1074 raxSeek(&si->ri,"<=",(unsigned char*)si->end_key,
1075 sizeof(si->end_key));
1076 if (raxEOF(&si->ri)) raxSeek(&si->ri,"$",NULL,0);
1077 } else {
1078 raxSeek(&si->ri,"$",NULL,0);
1079 }
1080 }
1081 si->pstream = s;
1082 si->lp = NULL; /* There is no current listpack right now. */
1083 si->lp_ele = NULL; /* Current listpack cursor. */
1084 si->rev = rev; /* Direction, if non-zero reversed, from end to start. */
1085}
1086
1087/* Return 1 and store the current item ID at 'id' if there are still
1088 * elements within the iteration range, otherwise return 0 in order to

Callers 8

streamDeleteItemFunction · 0.85
streamLastValidIDFunction · 0.85
streamReplyWithRangeFunction · 0.85
xclaimCommandFunction · 0.85
xorObjectDigestFunction · 0.85
RM_StreamIteratorStartFunction · 0.85
rewriteStreamObjectFunction · 0.85

Calls 4

streamEncodeIDFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxEOFFunction · 0.85

Tested by

no test coverage detected