//
// Copyright 2003, Juan Segarra Flor
//
// This is part of videocache
//
// Videocache 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.
//
// Videocache 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 Foobar; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

#include <stdlib.h>
#include <iostream>
#include <math.h>

#ifndef CACHE_TREE
#define CACHE_TREE

typedef struct node{
  int id;  // node identificator
  int linkid;  // link node-parent identificator
  node* parent; // pointer to parent
  //unsigned int bw; // link node-parent bandwidth
  unsigned long size; // cache size
  node* nextchild;// pointer to next node in level
  int userlinkid; // shared link between users in last caches
} t_node;

class cachetree {
  int depth; // tree depth
  int nodechildren; // children each node
  int maxlinks; // max links
  int users_each_node; // num users each node;
  node* parent; // pointer to root
  node* children; // pointer to first leaf node
  void createson(t_node* parent,int nchild,int* id,
		int* linkid,int ndepth,t_node **nextson);
  int getnodesindepth(int ndepth);
  t_node* searchnode(int nid);
 public:
  cachetree(int tdepth,int nchild,int nusers);
  int getdepth() {return depth;};
  int getmaxlinks() {return maxlinks;};
  int getnodeid(int depth,int numnode);
  int *getcachesinlevel(int ndepth);
  int *getbestroute(int *nodelist,long user);//first leafcache
  int getlinkdepth(int link);
  void printtree();
  void printlinks();
  int getnodedepth(int numnode);
  int getlinknodeparent(int nid);
};

#endif
