--- /dev/null
+Try to improve 'sameStr' by maybe not having to check s2[i2]
#include "repl.h"
#include "parser.h"
#include "storage.h"
+#include "strings.h"
-
-#endif
\ No newline at end of file
+#endif
#include "db.h"
-uint16_t len(const char *s){
- uint16_t l = -1;
- while(s[++l]);
- return l;
-}
-
-bool sameStr(const char* s1, const char *s2){
- uint16_t i1 = 0, i2 = 0;
- while(s1[i1] && s2[i2] && s1[i1] == s2[i2])
- ++i1, ++i2;
- return !s1[i1] && !s2[i2];
-}
-
int handleMetaCommand(inputBuffer *in){
if(sameStr(in->buffer, ".exit")){
freeInputBuffer(in);
}else{
printf("normal command\n");
}
-}
\ No newline at end of file
+}
} metaCommandStatus;
-uint16_t len(const char *s);
-
-bool sameStr(const char* s1, const char *s2);
-
int handleMetaCommand(inputBuffer *in);
int handleInput(inputBuffer *in);
-#endif
\ No newline at end of file
+#endif
memcpy(nr->path, path, MAXPATH);
memcpy(nr->tags, "\0", MAXTAGS);
nr->numTags = 0;
+ nr->lenTags = 0;
return nr;
}
}
r->tags[tagnum] = '\0';
r->numTags = l;
+ r->lenTags = tagnum;
}
// Remove a tag from the tags array in the row r
}
r->tags[tagnum] = '\0';
r->numTags = l;
-}
\ No newline at end of file
+ r->lenTags = tagnum;
+}
typedef struct{
char path[MAXPATH];
char tags[MAXTAGS];
- int numTags;
+ uint16_t numTags;
+ uint16_t lentags;
+
} row;
void removeTag(row *r, char *tag);
-#endif
\ No newline at end of file
+#endif
--- /dev/null
+#include "db.h"
+
+
+uint16_t len(const char *s){
+ uint16_t l = -1;
+ while(s[++l]);
+ return l;
+}
+
+bool sameStr(const char *s1, const char *s2){
+ uint16_t i1 = 0, i2 = 0;
+ while(s1[i1] && s2[i2] && s1[i1] == s2[i2])
+ ++i1, ++i2;
+ return !s1[i1] && !s2[i2];
+}
+
+
+static int *table(char *y, int n, char sep){
+ int *tb = calloc(n, sizeof(int));
+ if(tb == NULL){
+ fprintf(stderr, "Error callocating array (table)");
+ exit(EXIT_FAILURE);
+ }
+
+ int lSep = n-1;
+ for(int i = n-1; i >= 0; --i){
+ if(y[i] == sep){
+ tb[i] = 1;
+ lSep = i;
+ }else if(y[i] != '\0'){
+ tb[i] = lSep-i;
+ }
+ }
+ return tb;
+}
+
+
+ssize_t strInTags(const char *tags, int n, const char *ndl, int m, char sep){
+ int *tb = table(tags, n, sep);
+
+ for(int i = 0; i < n; ){
+ int j = 0;
+ while(j < m && tags[i+j] == ndl[j]){
+ ++j;
+ }
+ if(j == m){
+ return i;
+ }
+ if(tags[i+j] != ndl[j]){
+ i += tb[i];
+ }
+ }
+ return -1;
+}
+
--- /dev/null
+#ifndef STRINGS_H
+#define STRINGS_H
+
+#include "db.h"
+
+
+uint16_t len(const char *s);
+
+bool sameStr(const char *s1, const char *s2);
+
+ssize_t strInTags(const char *tags, int n, const char *ndl, int m, char sep);
+
+
+#endif