/* -------------------------------------------------------------------------
//MyCell Library - MyCell version 1.0
//
// This file is a part of the MyCell Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.txt at this distribution. By using
// this software in any fashion, you are agreeing to be bound by the terms
// of this license. You must not remove this notice, or any other, from
// this software.
//
// Creator: yanxueming
// Email: xueming.yan@gmail.com
// -----------------------------------------------------------------------*/
#pragma once
#include <map>
using namespace std;
namespace mycell{
//[beg,end]
template<typename k,typename v>
void delete_cols(map<k,v>& m,int beg,int end)
{
int const cnt=end-beg+1;
map<k,v> mt;
for(map<k,v>::const_iterator it=m.begin();it!=m.end();++it){
const int nK=it->first;
if(nK<beg){
mt.insert(*it);
}else if(nK>end){
mt.insert(make_pair(nK-cnt,it->second));
}
}
m.swap(mt);
/*
vector<pair<k,v> > vec;
for(map<k,v>::iterator it=m.begin();it!=m.end();)
{
if(it->first>=beg && it->first<=end){
it=m.erase(it);
continue;
}else if(it->first > end){
vec.push_back(make_pair(it->first-cnt,it->second));
it=m.erase(it);
continue;
}
++it;
}
for(vector<pair<k,v> >::const_iterator it=vec.begin();it!=vec.end();++it)
m.insert(*it);
*/
}
//��begǰ����nCount��
template<typename k,typename v>
void insert_cols(map<k,v>& m,int beg,int nCount)
{
//int const end=beg+nCount;
map<k,v> mt;
for(map<k,v>::const_iterator it=m.begin();it!=m.end();++it){
const int nK=it->first;
if(nK<beg){
mt.insert(*it);
}else{
mt.insert(make_pair(nK+nCount,it->second));
}
}
m.swap(mt);
/*
vector<pair<k,v> > vec;
for(map<k,v>::iterator it=m.begin();it!=m.end();)
{
if(it->first>=beg){
vec.push_back(make_pair(it->first+nCount,it->second));
it=m.erase(it);
continue;
}
++it;
}
for(vector<pair<k,v> >::const_iterator it=vec.begin();it!=vec.end();++it)
{
m.insert(*it);
}
*/
}
}//namespace mycell