On Fri, 2019-02-15,
rgla...@sfu.ca wrote:
> I have the following struct:
I note that there's nothing in the text about "turning bits into
integers". Was the subject line an error, or a clue to what you
really wanted to ask about?
> struct NonlocalBonds {
> std::vector<unsigned int> k;
> unsigned int l;
>
> unsigned int bond = 0;
> bond ^= 1<<k;
I have no idea what this is supposed to mean. It's better to show
code that at least compiles.
> unsigned int operator()(unsigned int i, unsigned int j) const {
> assert(j > i);
>
> if ((j-i) % 4 != 0 || (j-i) / 4 != l)
> return k.end();
>
> if ((i-2) % 4 != 0 || std::find(k.begin(), k.end(), (i-2) / 4) == k.end())
> return k.end();
>
> return ((1-2 / 4);
> }
> };
This cannot compile, either. k.end() is an iterator and ((1-2 / 4) is
a syntax error.
You seem to have mixed up 1 and l, too. Never use l (or O) as
identifiers.
> Where k and l are contained within a json output file, and are shown below:
>
> "nonlocal_bonds": {
> "k": [0, 4, 9, 11, 16, 18, 23, 27, 29, 32, 35, 38, 41, 45, 47, 50, 52, 56],
> "l": 5
> },
That they come from a file in a certain format is irrelevant. Instead
show that you construct a NonlocalBonds with those values. Like, a
main() with a test case.
> I am using i and j, which are unsigned ints
Like the code says.
> whose values are specified in another function,
Like the code says (they are parameters).
> to calculate l and k from the expressions (j-i) / 4 and (i-2) /
> 4). If the calculated l and k are matched with the l and k from my
> output file, I want to return the k that matched with the value of k
> in the output file. Then, I want to do bond ^= 1<<k on the returned
> k.
>
> I know there are lots of errors in here, and I need help.
My main issue is you're writing a lot about the low-level operations
you intend to execute, but nothing about what you're trying to
accomplish. Unless the subject line is a clue, or unless Nonlocal
Bonds are well-known in some problem domain I'm ignorant
of. (Economics? Chemistry? Topology?)
I think you'd have more luck if you explained your problem from the
beginning.
> I think I am supposed to be returning std::find(k.begin(), k.end(),
> (i-2) / 4)) - k.end() or something,
Why? Note that k.end() is always "larger or equal to" find(...).
> and the type of operator() is
> probably wrong, and I don't know how to tell "bond" that the k in
> this equation is the returned value.
I don't know who "bond" is, and I see no equation.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/
snipabacken.se> O o .