From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/hdb/sortable.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/hdb/sortable.cc (limited to 'src/hdb/sortable.cc') diff --git a/src/hdb/sortable.cc b/src/hdb/sortable.cc new file mode 100644 index 0000000..39adf58 --- /dev/null +++ b/src/hdb/sortable.cc @@ -0,0 +1,81 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +using namespace std; + +int int_stream::appc(char c) { return val=c,1; } +int int_stream::appi(int i) { return val=i,1; } +int int_stream::appf(double f) { return val=(int)f,1; } +int int_stream::apps(const sref& s) { return val=atoi(s),s.size(); } + +/////////////////////////////////////////////////// + +record_t::record_t(const spile& list) +{ + pos[0].set(0); + for(int i=0;i p=equal_range(begin(),end(),idx_t(t,0),comp); + return p.first!=p.second?p.first-begin():-1; +} + +int indexmap::add(const sref& t,record_t* rec) +{ + idx_t tmp(t,rec); + pair p=equal_range(begin(),end(),tmp,comp); + if(p.first!=p.second) return &(*p.first=tmp)-begin(); + else return insert(p.second,tmp)-begin(); +} + +void indexmap::sort(const op_t* op) +{ + comp.func=op->f2; + ::sort(begin(),end(),comp); +} -- cgit v1.2.3