'Merge a list of Block objects from the NN into the list
of cached blocks.
If the set of blocks overlaps, the new blocks take precedence.'

def insert_new_blocks(self, new_blocks):

    blocks_dict = dict(((b.blockId, b) for b in self.blocks))
    for nb in new_blocks:
        blocks_dict[nb.blockId] = nb
    block_list = blocks_dict.values()
    block_list.sort(cmp=(lambda a, b: cmp(a.startOffset, b.startOffset)))
    self.blocks = block_list
