PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llcommonutils.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 56 lines | 21 code | 7 blank | 28 comment | 0 complexity | 7cc12e7667acf38fb2eb4127679e6e33 MD5 | raw file
 1/**
 2 * @file llcommonutils.h
 3 * @brief Commin utils
 4 *
 5 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "linden_common.h"
28#include "llcommonutils.h"
29
30void LLCommonUtils::computeDifference(
31	const uuid_vec_t& vnew,
32	const uuid_vec_t& vcur,
33	uuid_vec_t& vadded,
34	uuid_vec_t& vremoved)
35{
36	uuid_vec_t vnew_copy(vnew);
37	uuid_vec_t vcur_copy(vcur);
38
39	std::sort(vnew_copy.begin(), vnew_copy.end());
40	std::sort(vcur_copy.begin(), vcur_copy.end());
41
42	size_t maxsize = llmax(vnew_copy.size(), vcur_copy.size());
43	vadded.resize(maxsize);
44	vremoved.resize(maxsize);
45
46	uuid_vec_t::iterator it;
47	// what was removed
48	it = set_difference(vcur_copy.begin(), vcur_copy.end(), vnew_copy.begin(), vnew_copy.end(), vremoved.begin());
49	vremoved.erase(it, vremoved.end());
50
51	// what was added
52	it = set_difference(vnew_copy.begin(), vnew_copy.end(), vcur_copy.begin(), vcur_copy.end(), vadded.begin());
53	vadded.erase(it, vadded.end());
54}
55
56// EOF