Implement pack/unpack function in nearest_neighbor