Merge branch 'master' of https://github.com/jzck/libft
"merge with hashtab"
This commit is contained in:
commit
fe85569a79
5 changed files with 141 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ INC_DIR = includes/
|
|||
OBJ_DIR = objs/
|
||||
|
||||
SRC_BASE = \
|
||||
rs/rs.c\
|
||||
btree/btree_apply_by_level.c\
|
||||
btree/btree_apply_infix.c\
|
||||
btree/btree_apply_prefix.c\
|
||||
|
|
@ -138,6 +139,7 @@ printing/ft_putchar.c\
|
|||
printing/ft_putendl.c\
|
||||
printing/ft_putnbr.c\
|
||||
printing/ft_putstr.c\
|
||||
printing/hexdump.c\
|
||||
sstr/ft_sstradd.c\
|
||||
sstr/ft_sstrcat.c\
|
||||
sstr/ft_sstrdel.c\
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# define FT_TRY(a,b) ((a) ? (a) : (b))
|
||||
|
||||
# include <string.h>
|
||||
# include <errno.h>
|
||||
# include <unistd.h>
|
||||
|
|
@ -24,6 +26,7 @@
|
|||
# include "error.h"
|
||||
# include "color.h"
|
||||
# include "cliopts.h"
|
||||
# include "rs.h"
|
||||
|
||||
# include "lst.h"
|
||||
# include "dlst.h"
|
||||
|
|
@ -87,6 +90,8 @@ void ft_putendl_fd(char const *s, int fd);
|
|||
void ft_putnbr_fd(long n, int fd);
|
||||
void ft_putnbr_hex_fd(long n, int fd);
|
||||
|
||||
void hexdump(void *pAddressIn, long lSize);
|
||||
|
||||
void *ft_realloc(void *data, int size);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
21
libft/includes/rs.h
Normal file
21
libft/includes/rs.h
Normal 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
|
||||
57
libft/srcs/printing/hexdump.c
Normal file
57
libft/srcs/printing/hexdump.c
Normal 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
56
libft/srcs/rs/rs.c
Normal 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);
|
||||
}
|
||||
Loading…
Reference in a new issue