From a1bb8c7ff906f984f737aa2fe5133d7dff1dec57 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 14 Dec 2011 01:38:14 +0000 Subject: [PATCH] svn path=/trunk/boinc/; revision=24791 --- ssim/des.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ssim/des.h b/ssim/des.h index 006368d4b6..4e0c0b18e9 100644 --- a/ssim/des.h +++ b/ssim/des.h @@ -1,8 +1,32 @@ +// This file is part of BOINC. +// http://boinc.berkeley.edu +// Copyright (C) 2011 University of California +// +// BOINC is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// BOINC 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with BOINC. If not, see . + +// The world's smallest discrete event simulator. +// Uses the STL "heap" data structure for efficient event storage. + #include #include using std::vector; +// base class for events. +// t is the time when the event occurs. +// handle() is what you want to happen then +// struct EVENT { double t; virtual void handle(){} @@ -15,11 +39,17 @@ bool compare(EVENT* e1, EVENT* e2) { struct SIMULATOR { vector events; double now; + + // add an event + // void insert(EVENT* e) { //printf("adding %x\n", e); events.push_back(e); push_heap(events.begin(), events.end(), compare); } + + // remove an event + // void remove(EVENT* e) { vector::iterator i; //printf("removing %x\n", e); @@ -33,6 +63,9 @@ struct SIMULATOR { } //printf("%x not found\n", e); } + + // run the simulator for the given time period + // void simulate(double dur) { while (events.size()) { EVENT* e = events.front();