开发者

Best style for iterating through two lists in unison

开发者 https://www.devze.com 2023-01-20 14:58 出处:网络
Here is what I just wrote: public void mutate(){ ListIterator<Double> git = genome.listIterator();

Here is what I just wrote:

 public void mutate(){
    ListIterator<Double> git = genome.listIterator();
    Iterator开发者_开发问答<Double> mit = mutationStrategies.iterator();
    while (git.hasNext() && mit.hasNext()){
        git.set(alleleUpdate(git.next(), mit.next()));
    }

}

Is this the most efficient and clearest way of doing that? All that is necessary to know is that the genome list is setting its values according to some function that takes its current value and the current value of mutationStrategies. (If your into evolutionary stuff, this is for an Evolution Strategies algorithm).


It's hard to imagine how it could be tighter. "Replace each git (whatever those are) with a mutated version of itself, stopping if we run out of mutation strategies."

0

精彩评论

暂无评论...
验证码 换一张
取 消