Sketch: we have integrated sketch into TinyDB
Author: Bingsheng He (saven@cs.ust.hk)

/*									tab:4
 * "Copyright (c) 2000-2003 The Regents of the University  of California.  
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 * Copyright (c) 2002-2003 Intel Corporation
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached INTEL-LICENSE     
 * file. If you do not find these files, copies can be found by writing to
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
 * 94704.  Attention:  Intel License Inquiry.
 */
********************************************************************************

Copyright (c) 2004-2005, The Hong Kong University of Science and Technology (HKUST)
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
  are met:
 
    * Redistributions of source code must retain the above copyright notice, 
      this list of conditions, the authors and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions, the authors and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the university nor the names of its 
      contributors may be used to endorse or promote products derived from 
      this software without specific prior written permission.
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  POSSIBILITY OF SUCH DAMAGE.


********************************************************************************



README:


=========================================================================================
Description:
Detailed description of sketch can be found in the following paper:
[1] Jeffrey Considine, Feifei Li, George Kollios, and John Byers. Approximate Aggregation Techniques for Sensor Databases, ICDE 2004. 
[2] Philippe Flajolet and G. Nigel Martin. Probabilistic Counting Algorithms for Data Base Applications. Journal of Computer and System Sciences, Vol. 31, Issue 2, 1985.

We implemented SKETCH [1] on top of TinyDB for three aggregation operators, including SUM, COUNT, and AVG.  
We followed most of the implementation strategies proposed in the original SKETCH paper [1].  
And, we have made the following modifications:
(1)  We modified the routing layer of TinyDB to enable multiple paths, since SKETCH was proposed to run in multi-path sensor networks.
(2)  Instead of using 20 16-bit bitmaps in the original SKETCH paper [1], we used 10 16-bit bitmaps for sketches. 
With the original compression scheme in SKETCH, this setting yields a good tradeoff between data accuracy (quality) and power consumption in our experiments.
(3)  We used the hash function proposed by Flajolet [2], as we have no information about the exact hash function used in the original SKETCH.
  
-------------------------------------------------------------------------------------------


The source files are organized into the directories of TinyDB\ and TinyDB\Aggregates\.
Changes have been made to TinyDB's source code to enable sketch in TinyDB in the following source files:

.\TinyDB\
	TinyDB.h
	AggOperator.nc
	SelOperator.nc
	TupleRouterM.nc
	TinyDBAttr.nc
	TinyDBAttrM.nc
	Network.nc
	NetworkMultiHopM.nc

.\TinyDB\Aggregates\
	CountM.nc
	Aggregates.h
	SumM.nc
	AvgM.nc
	
.\Route\	
	MultiHopRouter.nc
	MultiHopRouteSelect.nc
	MultiHopLEPSM.nc
	MultiHopEngineM.nc
	MultiHop.h
	


-------------------------------------------------------------------------------------------------


Usage:

1. Put the skecth-based TinyDB and Route source code to \opt\tinyos-1.x\tos\lib in TinyOS directory.
 
2. Followed the README of VMNET.
-------------------------------------------------------------------------------------------------
Date: June 22, 2005
==========================================================================================================