shithub: asif

Download patch

ref: 1ef2d33d7af26144ea8109e1017b745b98f49846
parent: f8978196906ee7a57ebedf6c5a7d09ae1bba89a6
author: qwx <qwx@sciops.net>
date: Sat Aug 15 17:33:25 EDT 2020

more silly reshuffles

split utils into individual files, easier to manage

--- a/asif.h
+++ b/asif.h
@@ -1,11 +1,10 @@
-typedef struct VArray VArray;
 typedef struct String String;
-
 struct String{
 	char *s;
 	int n;
 };
 
+typedef struct VArray VArray;
 struct VArray{
 	int nelem;
 	int elsize;
@@ -13,22 +12,13 @@
 	int bufsize;
 	void *p;
 };
-
-void*	erealloc(void*, ulong, ulong);
-void*	emalloc(ulong);
 void	vfree(VArray*);
 VArray*	vinsert(VArray*, char*);
 VArray*	valloc(ulong, int);
 
-#define MIN(a,b)	((a) < (b) ? (a) : (b))
-#define MAX(a,b)	((a) > (b) ? (a) : (b))
-
-
 VArray*	naivestrfind(String, String);
 
-
 typedef struct Pairheap Pairheap;
-
 struct Pairheap{
 	double n;
 	void *aux;
@@ -36,8 +26,13 @@
 	Pairheap *left;
 	Pairheap *right;
 };
-
 void	nukequeue(Pairheap**);
 Pairheap*	popqueue(Pairheap**);
 void	decreasekey(Pairheap*, double, Pairheap**);
 void	pushqueue(double, void*, Pairheap**);
+
+void*	erealloc(void*, ulong, ulong);
+void*	emalloc(ulong);
+
+#define MIN(a,b)	((a) < (b) ? (a) : (b))
+#define MAX(a,b)	((a) > (b) ? (a) : (b))
--- /dev/null
+++ b/emalloc.c
@@ -1,0 +1,23 @@
+#include <u.h>
+#include <libc.h>
+#include "asif.h"
+
+void *
+erealloc(void *p, ulong n, ulong oldn)
+{
+	if((p = realloc(p, n)) == nil)
+		sysfatal("realloc: %r");
+	setrealloctag(p, getcallerpc(&p));
+	return p;
+}
+
+void *
+emalloc(ulong n)
+{
+	void *p;
+
+	if((p = mallocz(n, 1)) == nil)
+		sysfatal("emalloc: %r");
+	setmalloctag(p, getcallerpc(&n));
+	return p;
+}
--- a/utils.c
+++ /dev/null
@@ -1,62 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include "asif.h"
-
-enum{
-	VAdefsize = 1024,
-};
-
-void *
-erealloc(void *p, ulong n, ulong oldn)
-{
-	if((p = realloc(p, n)) == nil)
-		sysfatal("realloc: %r");
-	setrealloctag(p, getcallerpc(&p));
-	return p;
-}
-
-void *
-emalloc(ulong n)
-{
-	void *p;
-
-	if((p = mallocz(n, 1)) == nil)
-		sysfatal("emalloc: %r");
-	setmalloctag(p, getcallerpc(&n));
-	return p;
-}
-
-void
-vfree(VAarray *v)
-{
-	free(v->p);
-	free(v);
-}
-
-VArray*
-vinsert(VArray *v, char *)
-{
-	int off;
-
-	off = v->nelem * v->elsize;
-	if(v->nelem++ >= v->bufsize){
-		v->p = erealloc(v->p, v->bufsize * 2, v->bufsize);
-		v->bufsize *= 2;
-		v->vsize *= 2;
-	}
-	memcpy(v->p+off, u, v->elsize);
-}
-
-VArray*
-valloc(ulong n, int elsize)
-{
-	VArray *v;
-
-	v = emalloc(sizeof *p);
-	v->nelem = 0;
-	v->elsize = elsize;
-	v->vsize = MIN(n, VAdefsize);
-	v->bufsize = v->vsize * elsize;
-	v->p = emalloc(v->bufsize);
-	return v;
-}
--- /dev/null
+++ b/varray.c
@@ -1,0 +1,42 @@
+#include <u.h>
+#include <libc.h>
+#include "asif.h"
+
+enum{
+	VAdefsize = 1024,
+};
+
+void
+vfree(VAarray *v)
+{
+	free(v->p);
+	free(v);
+}
+
+VArray*
+vinsert(VArray *v, char *)
+{
+	int off;
+
+	off = v->nelem * v->elsize;
+	if(v->nelem++ >= v->bufsize){
+		v->p = erealloc(v->p, v->bufsize * 2, v->bufsize);
+		v->bufsize *= 2;
+		v->vsize *= 2;
+	}
+	memcpy(v->p+off, u, v->elsize);
+}
+
+VArray*
+valloc(ulong n, int elsize)
+{
+	VArray *v;
+
+	v = emalloc(sizeof *p);
+	v->nelem = 0;
+	v->elsize = elsize;
+	v->vsize = MIN(n, VAdefsize);
+	v->bufsize = v->vsize * elsize;
+	v->p = emalloc(v->bufsize);
+	return v;
+}