Skip to content

Commit

Permalink
update libutil
Browse files Browse the repository at this point in the history
  • Loading branch information
ideawu committed Nov 29, 2014
1 parent 5b328d0 commit fe30eaa
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
84 changes: 84 additions & 0 deletions src/util/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright (c) 2012-2014 The icomet Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
*/
#ifndef UTIL_LIST_H
#define UTIL_LIST_H

template <class T>
class LinkedList{
public:
class Iterator{
private:
T p;
public:
friend class LinkedList;

T next(){
T ret = p;
if(p){
p = p->next;
}
return ret;
}
};
friend class Iterator;
public:
int size;
T head;
T tail;

LinkedList(){
size = 0;
head = NULL;
tail = NULL;
}

Iterator iterator(){
Iterator it;
it.p = this->head;
return it;
}

bool empty() const{
return size == 0;
}

void remove(T t){
this->size --;
if(t->prev){
t->prev->next = t->next;
}
if(t->next){
t->next->prev = t->prev;
}
if(this->head == t){
this->head = t->next;
}
if(this->tail == t){
this->tail = t->prev;
}
}

T pop_front(){
T t = this->head;
this->remove(t);
return t;
}

void push_back(T t){
this->size ++;
t->prev = this->tail;
t->next = NULL;
if(this->tail){
this->tail->next = t;
}else{ // both head and tail is empty
this->head = t;
}
this->tail = t;
}
};


#endif
18 changes: 17 additions & 1 deletion src/util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ found in the LICENSE file.
#ifndef UTIL_LOG_H
#define UTIL_LOG_H

#include "../include.h"
#include <inttypes.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <assert.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>

class Logger{
Expand Down

0 comments on commit fe30eaa

Please sign in to comment.