merged new htb changes

This commit is contained in:
Jack Halford 2017-06-15 09:52:36 +02:00
commit 9dc57f5cde
31 changed files with 422 additions and 17 deletions

View file

@ -23,6 +23,7 @@ INC_DIR = includes/
OBJ_DIR = objs/ OBJ_DIR = objs/
SRC_BASE = \ SRC_BASE = \
rs/rs.c\
btree/btree_apply_by_level.c\ btree/btree_apply_by_level.c\
btree/btree_apply_infix.c\ btree/btree_apply_infix.c\
btree/btree_apply_prefix.c\ btree/btree_apply_prefix.c\
@ -102,6 +103,7 @@ lst/ft_lstnadd.c\
lst/ft_lstnew.c\ lst/ft_lstnew.c\
lst/ft_lstnew_range.c\ lst/ft_lstnew_range.c\
lst/ft_lstsort.c\ lst/ft_lstsort.c\
lst/lst_insert_sort.c\
lst/pop.c\ lst/pop.c\
lst/push.c\ lst/push.c\
lst/top.c\ lst/top.c\
@ -137,6 +139,7 @@ printing/ft_putchar.c\
printing/ft_putendl.c\ printing/ft_putendl.c\
printing/ft_putnbr.c\ printing/ft_putnbr.c\
printing/ft_putstr.c\ printing/ft_putstr.c\
printing/hexdump.c\
sstr/ft_sstradd.c\ sstr/ft_sstradd.c\
sstr/ft_sstrcat.c\ sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\ sstr/ft_sstrdel.c\
@ -196,6 +199,13 @@ time/ft_mytime_free.c\
time/ft_mytime_get.c\ time/ft_mytime_get.c\
time/ft_time_isrecent.c\ time/ft_time_isrecent.c\
sys/open_new.c sys/open_new.c
htb/ft_hash_string.c\
htb/hashtab_init.c\
htb/hashtab_insert.c\
htb/hashtab_lookup.c\
htb/hashtab_remove.c\
htb/hashtab_destroy.c\
htb/hashtab_print.c\
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ /* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
/* Updated: 2017/03/14 17:40:20 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:31:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */ /* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */
/* Updated: 2017/03/07 17:25:50 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:30:42 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
/* Updated: 2017/04/02 20:45:00 by jhalford ### ########.fr */ /* Updated: 2017/05/15 17:37:29 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

46
libft/includes/hashtab.h Normal file
View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:16:49 by ariard #+# #+# */
/* Updated: 2017/05/16 21:03:50 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HASHTAB_H
# define HASHTAB_H
# include "libft.h"
struct s_hashtab
{
int capacity;
int size;
int (*hashfunc)(const void *key, int capacity);
struct s_list **head;
};
typedef struct s_hashtab t_hashtab;
void hashtab_init(t_hashtab *htb, int capacity,
int (*hashfunc)(const void *key, int size));
int hashtab_insert(t_hashtab *htb, struct s_list *new, void *key,
int (*match)(const void *data_ref, const void *key));
struct s_list *hashtab_lookup(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key));
struct s_list *hashtab_remove(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key));
void hashtab_destroy(t_hashtab *htb, void (*destroy)());
void hashtab_print(t_hashtab *htb, int (*printer)());
int ft_hash_string(const void *key, int size);
#endif

View file

@ -6,13 +6,15 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2017/04/03 16:51:25 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:47:18 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef LIBFT_H #ifndef LIBFT_H
# define LIBFT_H # define LIBFT_H
# define FT_TRY(a,b) ((a) ? (a) : (b))
# include <string.h> # include <string.h>
# include <errno.h> # include <errno.h>
# include <unistd.h> # include <unistd.h>
@ -24,10 +26,12 @@
# include "error.h" # include "error.h"
# include "color.h" # include "color.h"
# include "cliopts.h" # include "cliopts.h"
# include "rs.h"
# include "lst.h" # include "lst.h"
# include "dlst.h" # include "dlst.h"
# include "btree.h" # include "btree.h"
# include "hashtab.h"
# include "str.h" # include "str.h"
# include "sstr.h" # include "sstr.h"
@ -86,6 +90,8 @@ int ft_putendl_fd(char const *s, int fd);
int ft_putnbr_fd(long n, int fd); int ft_putnbr_fd(long n, int fd);
int ft_putnbr_hex_fd(long n, int fd); int ft_putnbr_hex_fd(long n, int fd);
void hexdump(void *pAddressIn, long lSize);
void *ft_realloc(void *data, int size); void *ft_realloc(void *data, int size);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
/* Updated: 2017/03/28 20:34:27 by jhalford ### ########.fr */ /* Updated: 2017/05/20 20:01:20 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -85,4 +85,7 @@ int ft_diff(void *a, void *b);
t_list *ft_id(t_list *a); t_list *ft_id(t_list *a);
t_list *ft_lst_at(t_list *list, unsigned int nbr); t_list *ft_lst_at(t_list *list, unsigned int nbr);
void lst_insert_sort(t_list **head,
int (cmp)());
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */ /* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:30:35 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

21
libft/includes/rs.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef LIBFT_RS_H
# define LIBFT_RS_H
#include <float.h>
#include <dlfcn.h>
extern struct s_stats {
int count;
double min;
double max;
double avg;
double m;
double stdev;
double var;
} g_rs;
void rs_clear();
void rs_push(double n);
void rs_calcmore();
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
/* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:30:50 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
/* Updated: 2017/03/20 21:06:28 by jhalford ### ########.fr */ /* Updated: 2017/05/15 19:08:35 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/02 16:35:24 by ariard #+# #+# */
/* Updated: 2017/05/16 17:33:47 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
int ft_hash_string(const void *key, int size)
{
const char *ptr;
unsigned int tmp;
unsigned int val;
val = 0;
ptr = key;
while (*ptr != '\0')
{
val = (val << 4) + (*ptr);
if ((tmp = (val & 0xf0000000)))
{
val = val ^ (tmp >> 24);
val = val ^ tmp;
}
ptr++;
}
return (val % size);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_destroy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 21:35:07 by ariard #+# #+# */
/* Updated: 2017/05/16 20:42:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
void hashtab_destroy(t_hashtab *htb, void (*destroy)())
{
int bucket;
bucket = -1;
while (++bucket < htb->capacity)
ft_lstdel(&htb->head[bucket], destroy);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:13:06 by ariard #+# #+# */
/* Updated: 2017/05/16 18:46:03 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
void hashtab_init(t_hashtab *htb, int capacity,
int (*hashfunc)(const void *key, int capacity))
{
htb->head = (t_list **)ft_memalloc(capacity * sizeof(*htb->head));
htb->capacity = capacity;
htb->size = 0;
htb->hashfunc = hashfunc;
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_insert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:30:39 by ariard #+# #+# */
/* Updated: 2017/05/16 21:05:19 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
int hashtab_insert(t_hashtab *htb, t_list *new, void *key,
int (*match)(const void *data_ref, const void *key))
{
int bucket;
if (hashtab_lookup(htb, key, match))
return (-1);
bucket = htb->hashfunc(key, htb->capacity);
ft_lsteadd(&htb->head[bucket], new);
htb->size++;
return (bucket);
}

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_lookup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:38:41 by ariard #+# #+# */
/* Updated: 2017/05/16 21:34:20 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *hashtab_lookup(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key))
{
int bucket;
if ((bucket = htb->hashfunc(key, htb->capacity)))
return (ft_lst_find(htb->head[bucket], key, match));
return (NULL);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/16 20:38:14 by ariard #+# #+# */
/* Updated: 2017/05/16 21:03:23 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void hashtab_print(t_hashtab *htb, int (*printer)())
{
int bucket;
bucket = -1;
while (++bucket != htb->capacity)
ft_lstiter(htb->head[bucket], printer, NULL);
}

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:46:48 by ariard #+# #+# */
/* Updated: 2017/05/16 17:34:56 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *hashtab_remove(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key))
{
t_list *data;
if ((data = hashtab_lookup(htb, key, match)))
return(ft_lst_removeif(&data, key, match));
return (NULL);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */ /* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */
/* Updated: 2016/12/07 18:07:31 by jhalford ### ########.fr */ /* Updated: 2017/05/15 21:35:59 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */
/* Updated: 2016/12/07 16:55:43 by jhalford ### ########.fr */ /* Updated: 2017/05/15 21:36:03 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
/* Updated: 2017/03/02 17:47:26 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:34:15 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */
/* Updated: 2017/01/10 11:07:37 by jhalford ### ########.fr */ /* Updated: 2017/05/16 21:27:55 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */
/* Updated: 2016/11/04 11:09:28 by jhalford ### ########.fr */ /* Updated: 2017/05/16 21:00:09 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:29 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:29 by jhalford #+# #+# */
/* Updated: 2016/11/04 11:09:29 by jhalford ### ########.fr */ /* Updated: 2017/05/16 21:00:19 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */ /* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:31:13 by jhalford ### ########.fr */ /* Updated: 2017/05/15 19:49:45 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */
/* Updated: 2017/03/08 00:19:43 by ariard ### ########.fr */ /* Updated: 2017/05/15 19:31:42 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */ /* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */ /* Updated: 2017/05/16 17:18:12 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst_insert_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/20 19:59:41 by ariard #+# #+# */
/* Updated: 2017/05/20 20:05:32 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void lst_insert_sort(t_list **head,
int (cmp)())
{
t_list *new;
t_list *ptr;
new = NULL;
while (*head)
{
ptr = *head;
*head = (*head)->next;
ft_lst_sorted_insert(&new, ptr, cmp);
}
*head = new;
}

View file

@ -0,0 +1,57 @@
#include <stdio.h>
#include <ctype.h>
#include "libft.h"
void hexdump(void *pAddressIn, long lSize)
{
char szBuf[100];
long lIndent = 1;
long lOutLen, lIndex, lIndex2, lOutLen2;
long lRelPos;
struct { char *pData; unsigned long lSize; } buf;
unsigned char *pTmp,ucTmp;
unsigned char *pAddress = (unsigned char *)pAddressIn;
buf.pData = (char *)pAddress;
buf.lSize = lSize;
while (buf.lSize > 0)
{
pTmp = (unsigned char *)buf.pData;
lOutLen = (int)buf.lSize;
if (lOutLen > 16)
lOutLen = 16;
// create a 64-character formatted output line:
sprintf(szBuf, " > "
" "
" %08lX", pTmp-pAddress);
lOutLen2 = lOutLen;
for(lIndex = 1+lIndent, lIndex2 = 53-15+lIndent, lRelPos = 0;
lOutLen2;
lOutLen2--, lIndex += 2, lIndex2++
)
{
ucTmp = *pTmp++;
sprintf(szBuf + lIndex, "%02X ", (unsigned short)ucTmp);
if(!isprint(ucTmp)) ucTmp = '.'; // nonprintable char
szBuf[lIndex2] = ucTmp;
if (!(++lRelPos & 3)) // extra blank after 4 bytes
{ lIndex++; szBuf[lIndex+2] = ' '; }
}
if (!(lRelPos & 3)) lIndex--;
szBuf[lIndex ] = '<';
szBuf[lIndex+1] = ' ';
printf("%s\n", szBuf);
buf.pData += lOutLen;
buf.lSize -= lOutLen;
}
}

56
libft/srcs/rs/rs.c Normal file
View file

@ -0,0 +1,56 @@
#include "libft.h"
#include <math.h>
struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0};
void rs_clear()
{
g_rs.count = 0;
g_rs.min = DBL_MAX;
g_rs.max = -DBL_MAX;
}
void rs_push(double n)
{
double delta;
g_rs.count++;
n < g_rs.min ? g_rs.min = n : (0);
n > g_rs.max ? g_rs.max = n : (0);
if (g_rs.count == 1)
{
g_rs.avg = n;
g_rs.m = 0;
}
else
{
delta = n - g_rs.avg;
g_rs.avg += delta / g_rs.count;
g_rs.m += delta * (n - g_rs.avg);
}
}
void rs_calcmore()
{
void *libm;
double (*sqrt)(double);
if (g_rs.count == 0)
{
g_rs.min = 0;
g_rs.max = 0;
}
if (g_rs.count < 2)
{
g_rs.var = 0;
g_rs.stdev = 0;
return ;
}
g_rs.var = g_rs.m / (g_rs.count - 1);
if ((libm = dlopen("libm.dylib", 0)) == NULL)
printf("%s\n", dlerror());
else if ((sqrt = dlsym(libm, "sqrt")) == NULL)
printf("%s\n", dlerror());
else
g_rs.stdev = sqrt(g_rs.var);
}

View file

@ -1,5 +1,9 @@
#include "libft.h" #include "libft.h"
/*
** If file already exists, create xxx(1) instead, etc up to 9
*/
int open_new(char *filename, int oflag) int open_new(char *filename, int oflag)
{ {
char *fname; char *fname;