index_fst_automation.c 2.7 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
dengyihao's avatar
dengyihao 已提交
15

dengyihao's avatar
dengyihao 已提交
16 17 18 19
#include "index_fst_automation.h"


// prefix query, impl later
dengyihao's avatar
dengyihao 已提交
20 21 22
static void* prefixStart(AutomationCtx *ctx) {  
  StartWithStateValue *data = (StartWithStateValue *)(ctx->data);
  return data;
dengyihao's avatar
dengyihao 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
};
static bool prefixIsMatch(AutomationCtx *ctx, void *data) {
  return true;
} 
static bool prefixCanMatch(AutomationCtx *ctx, void *data) {
  return true;
}
static bool prefixWillAlwaysMatch(AutomationCtx *ctx, void *state) {
  return true;
}
static void* prefixAccept(AutomationCtx *ctx, void *state, uint8_t byte) {
  return NULL;
}
static void* prefixAcceptEof(AutomationCtx *ctx, void *state) {
  return NULL;
}

// pattern query, impl later

static void* patternStart(AutomationCtx *ctx) {
  return NULL;
}
static bool patternIsMatch(AutomationCtx *ctx, void *data) {
  return true;
} 
static bool patternCanMatch(AutomationCtx *ctx, void *data) {
  return true;
} 
static bool patternWillAlwaysMatch(AutomationCtx *ctx, void *state) {
  return true;
}

static void* patternAccept(AutomationCtx *ctx, void *state, uint8_t byte) {
  return NULL;
}

static void* patternAcceptEof(AutomationCtx *ctx, void *state) {
  return NULL;
}

AutomationFunc automFuncs[]  = {{
    prefixStart,        
    prefixIsMatch, 
    prefixCanMatch,
    prefixWillAlwaysMatch,
    prefixAccept,
    prefixAcceptEof
  },  
  {
    patternStart,
    patternIsMatch,
    patternCanMatch,
    patternWillAlwaysMatch,
    patternAccept,
    patternAcceptEof
  }
dengyihao's avatar
dengyihao 已提交
79
  // add more search type
dengyihao's avatar
dengyihao 已提交
80 81 82
};

AutomationCtx* automCtxCreate(void *data, AutomationType type) {
dengyihao's avatar
dengyihao 已提交
83
  AutomationCtx *ctx = calloc(1, sizeof(AutomationCtx));
dengyihao's avatar
dengyihao 已提交
84 85
  if (ctx == NULL) { return NULL; }

dengyihao's avatar
dengyihao 已提交
86 87 88 89 90 91 92
  if (type == AUTOMATION_PREFIX) {
    StartWithStateValue *swsv = (StartWithStateValue *)calloc(1, sizeof(StartWithStateValue));   
    swsv->kind  = Done; 
    swsv->value = NULL; 
    ctx->data = (void *)swsv;
  } else if (type == AUTMMATION_MATCH) {
      
dengyihao's avatar
dengyihao 已提交
93 94
  } else {
    // add more search type
dengyihao's avatar
dengyihao 已提交
95
  }
dengyihao's avatar
dengyihao 已提交
96 97

  ctx->type = type;
dengyihao's avatar
dengyihao 已提交
98
  return ctx; 
dengyihao's avatar
dengyihao 已提交
99
} 
dengyihao's avatar
dengyihao 已提交
100
void automCtxDestroy(AutomationCtx *ctx) {
dengyihao's avatar
dengyihao 已提交
101 102 103 104
  if (ctx->type == AUTOMATION_PREFIX) {
    free(ctx->data);
  } else if (ctx->type == AUTMMATION_MATCH) {
  }
dengyihao's avatar
dengyihao 已提交
105 106
  free(ctx);
}