コード例 #1
0
ファイル: coding.cpp プロジェクト: songzheng/deprecated-code
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    
    FloatMatrix patch_feat;
    MatReadFloatMatrix(prhs[0], &patch_feat);
        
    CodingOpt opt;
    MatReadCodingOpt(prhs[1], &opt);
    
    InitCoding(&opt);
    
    FloatSparseMatrix patch_coding;
    plhs[0] = MatAllocateFloatSparseMatrix(&patch_coding, opt.length, patch_feat.width, opt.block_num, opt.block_size);    
    
    Coding(&patch_feat, &patch_coding, &opt);
    
}
コード例 #2
0
ファイル: HuffmanTree.c プロジェクト: apple006/Algorithm-C
int main() {
  int i, n=4, m;
  char test[] = "DBCBDABDABCDCADBD"; //需要转码的字符串
  char code[100],code1[100];
  char alphabet[] = {'A','B','C','D'}; //字符
  int w[] = {5,7,2,13}; //对应权重
  HuffmanTree *ht;
  HuffmanCode *hc;

  m = 2*n - 1; //所有结点树
  ht = (HuffmanTree *)malloc(sizeof(HuffmanTree)*(m+1));

  if(!ht) {
    printf("分配空间失败!\n");
    exit(0);
  }

  hc = (HuffmanCode *)malloc(sizeof(char *)*n);

  if(!hc) {
    printf("分配空间失败!\n");
    exit(0);
  }

  Create(ht, n, w); //创建赫夫曼树
  Coding(ht, n, hc);
  for(i=1;i<=n;i++) {
    printf("字母:%c,权重:%d,编码为:%s\n", alphabet[i-1],ht[i].weight, hc[i-1]);
  }

  Encode(hc, alphabet, test, code);
  printf("\n字符串:\n%s\n转换后为:\n%s\n", test, code);

  Decode(ht, n, code, alphabet,  code1);
  printf("\n编码:\n%s\n解码后为:\n%s\n", code, code1);
  return 0;
}