Question: Need some assistance with the token portion. If you could explain it in better terms I would appreciate it . Other info provided for some
Need some assistance with the token portion. If you could explain it in better terms I would appreciate it Other info provided for some context, but the token portion is what I need help understanding. The token template looks like, just swap greedy with strict for the other one:
template
tokeninfo getnexttokengreedyITERATOR begin, ITERATOR end, T delim
Iterator Algorithms Statistics and Output
In algos.h you will need to implement all of the templated functions that were declared in algos.decl.h
rangesum Iterate over the range provided, add up the elements, and return the sum. This is required to work with iterator
ranges containing any type that can be meaningfully added into a double.
rangeavg Iterate over the range provided, add up and count the elements, then calculate and return the average mean
as a double.
rangeminval Iterate over the range provided, keeping track of the minimum value found. Return that minimum value.
Calling this on an empty range is undefined behavior, so dont worry about handling it
rangemaxval Iterate over the range provided, keeping track of the maximum value found. Return that maximum value.
Calling this on an empty range is undefined behavior, so dont worry about handling it
rangecount Iterate over the range provided, counting the number of elements that occur within the range. Return that count.
tokeninfo This a struct If youre not familiar with structs, think of them as classes but with everything public by default
It will be used by the getnexttoken functions to track where successive calls left off so they can continue until the end.
tbegin Your functions will be responsible for setting this iterator to point to the beginning of the token found.
tend Your functions will be responsible for setting this iterator to point right after the last element of the token found.
tnext Your functions will be responsible for setting this iterator to point the beginning of the next token, or to then
actual end of the range if there are no further tokens.
begin Returns an iterator to the beginning of the token that was found. This is useful because it allows you to use
the rangebased for loop on this to iterate over the subrange represented.
end Returns the iterator representing the end of the halfopen range representing the token that was found.
getnexttokenstrict begin, end, delim getnexttokengreedy begin, end, delim These functions
will start at begin and iterate until it either reaches the end iterator, or finds an element in the range that has the value delim.
Your function will be responsible for setting the members of the tokeninfo returned appropriately. The tbegin member
will be set to the iterator representing the beginning of the token, and the tend member will be set to the location immediately
past the end of the token, or to end if we reach the end of the input range.
The tnext member of the tokeninfo struct returned must point to the beginning of the next token, or to the end of the
range if no more tokens are to be found. How this is determined will be the main difference between the strict and greedy
versions.
begin Where to begin the search for a delimiter.
end The end of the range to search. If we reach this, there are no more elements to form tokens with.
delim the delimiter value, when it is found in the range, it is used to indicate that one token has ended
Strict vs Greedy For the strict version, every delimiter begins a new token, and a delimiter found immediately after
another delimiter will indicate the presence of a zerolength token. This is useful for situations like tab or commaseparated
values files, where you want the delimiter to start a new field and would actually like to be able to leave fields blank.
For the greedy version, once a delimiter is found, the next token starts at the next position that is not a delimiter. That
means that if we have several delimiters in a row, they are eaten and do not indicate empty tokens. One time this can be
useful is in handling for whitespace in strings when you dont want the number of spaces to matter, which is the case when
parsing HTML or similar languages.
Let's do an example tokenizing of integers using as the delimiter
source sequence:
strict token :
strict token : empty
strict token : empty
strict token :
strict token :
greedy token :
greedy token :
greedy token :
Thanks!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
