我写的按日期归类的哈希表

   memset(pAppletData->fullpath,0,PHOTO_MAX_PATH);    sprintf(pAppletData->fullpath,"%s%s",pAppletData->selectpath,entry->d_name);

   if(pAppletData->filepStat == ListHead)    {     //creat     pS =(FiledataNode *)OS_Malloc(sizeof(FiledataNode));     pS->next = NULL;     pS->index = index;     //get entry data      strcpy(pS->fullpath,pAppletData->fullpath); //     strcat(pS->fullpath,entry->d_name);     // OS_TaskDelay(10); #ifdef WIN32     pS->datetime = i%8;     sprintf(pS->datetime_name, "%d-%d-%d",i%8,i%8,i%8);

#else

    ufs_stat(pAppletData->fullpath, &f_stat);     filedate = f_stat.st_mtime;     AF_PRINTF("fullpath: %s, /r/nyear(%d), month(%d), date(%d) /r/n",pAppletData->fullpath,(1980 + filedate.year),filedate.month,filedate.day);     pS->datetime = 19800000 + filedate.year*10000 + filedate.month*100 + filedate.day;     AF_PRINTF("----------------------------name =%s  index =%d/n",pS->fullpath,pS->index);     sprintf(pS->datetime_name, "%d-%d-%d",(1980 + filedate.year),filedate.month,filedate.day); #endif

//    strcpy(pS->datetime_name,pAppletData->pSVirtualDirArray->datetime_name);

    pSVirtualDirArray = (VirtualDirArray *)OS_Malloc(sizeof(VirtualDirArray));     pSVirtualDirArray->next = NULL;     pHeadVirtualDirArray = pSVirtualDirArray;     pSVirtualDirArray->childNode = pS;     pSVirtualDirArray->datetime = pS->datetime;     strcpy(pSVirtualDirArray->datetime_name,pS->datetime_name);

    pAppletData->nfilesCount++;     pAppletData->totalEntriesCount++;     pAppletData->filepStat = ListBody;       }    else  //Body    {     pS =(FiledataNode *)OS_Malloc(sizeof(FiledataNode));     pS->next = NULL;     pS->index = index;        //get fullpath and Time data     strcpy(pS->fullpath,pAppletData->fullpath); //    strcat(pS->fullpath,entry->d_name);     //OS_TaskDelay(10);    // AF_PRINTF("----------------------------name =%s  index =%d/n",pS->fullpath,pS->index); #ifdef WIN32     pS->datetime = i%8;     sprintf(pS->datetime_name, "%d-%d-%d",i%8,i%8,i%8); #else

    ufs_stat(pAppletData->fullpath, &f_stat);     filedate = f_stat.st_mtime;     AF_PRINTF("fullpath: %s, /r/nyear(%d), month(%d), date(%d) /r/n",pAppletData->fullpath,(1980 + filedate.year),filedate.month,filedate.day);     pS->datetime = 19800000 + filedate.year*10000 + filedate.month*100 + filedate.day;     AF_PRINTF("----------------------------name =%s  index =%d/n",pS->fullpath,pS->index);     sprintf(pS->datetime_name, "%d-%d-%d",(1980 + filedate.year),filedate.month,filedate.day); #endif         pSVirtualDirArray = pHeadVirtualDirArray;     findout = FALSE;     while(pSVirtualDirArray->next != NULL)     {      //time same

     if (pSVirtualDirArray->datetime == pS->datetime)

     {       FiledataNode *temp;       temp = pSVirtualDirArray->childNode;       pSVirtualDirArray->childNode = pS;       pS->next = temp;       findout = TRUE;       break;      }      pSVirtualDirArray = pSVirtualDirArray->next;     }    //the last one     if(pSVirtualDirArray->next == NULL)     {      if (pSVirtualDirArray->datetime == pS->datetime)      {       FiledataNode *temp;       temp = pSVirtualDirArray->childNode;       pSVirtualDirArray->childNode = pS;       pS->next = temp;       findout = TRUE;      }        }     if(findout != TRUE)     {      pSVirtualDirArray->next = (VirtualDirArray *)OS_Malloc(sizeof(VirtualDirArray));      pSVirtualDirArray = pSVirtualDirArray->next;      pSVirtualDirArray->next = NULL;      pSVirtualDirArray->childNode = pS;      pSVirtualDirArray->datetime = pS->datetime;      strcpy(pSVirtualDirArray->datetime_name,pS->datetime_name);      AF_PRINTF("fullpath: %s/r/n",pAppletData->fullpath);

    }      pAppletData->nfilesCount++;      pAppletData->totalEntriesCount++;     pAppletData->filepStat = ListBody;    }    //   if (pAppletData->nfilesCount==pAppletData->nfiles)    if ((i + 1) ==(pAppletData->totalEntries-1))    {     VirtualfolderSort(pHeadVirtualDirArray);     pAppletData->pHeadVirtualDirArray = pHeadVirtualDirArray;         pSVirtualDirArray = pHeadVirtualDirArray;         //count how many virual dir is.     for ( pAppletData->nVirualdirs = 0;pSVirtualDirArray != NULL;pAppletData->nVirualdirs++)     {      pSVirtualDirArray = pSVirtualDirArray->next;     }    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尽力帮助你。 哈希表是一种常用的数据结构,它允许你在常数时间内插入、查找和删除数据。它的原理是,通过哈希函数将数据映射到表中的桶里。 以下是一个示例的 C 语言哈希表的实现: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #define HASH_SIZE 10 typedef struct _hash_item { char *key; char *value; struct _hash_item *next; } hash_item; typedef struct _hash_table { hash_item *items[HASH_SIZE]; } hash_table; // 哈希函数,用于将键映射到表中的桶 unsigned long hash(char *str) { unsigned long hash = 5381; int c; while ((c = *str++)) { hash = ((hash << 5) + hash) + c; } return hash % HASH_SIZE; } // 初始化哈希表 void hash_table_init(hash_table *ht) { int i; for (i = 0; i < HASH_SIZE; i++) { ht->items[i] = NULL; } } // 向哈希表中插入一个项 void hash_table_insert(hash_table *ht, char *key, char *value) { unsigned long index = hash(key); hash_item *item = malloc(sizeof(hash_item)); item->key = strdup(key); item->value = strdup(value); item->next = ht->items[index]; ht->items[index] = item; } // 从哈希表中查找一个项 char *hash_table_lookup(hash_table *ht, char *key) { unsigned long index = hash(key); hash_item *item = ht->items[index]; while (item) { if (strcmp(item->key, key) == 0) { return item->value; } item = item->next; } return NULL; } // 从哈希表中删除一个项 void hash_table_delete(hash_table *ht, char *key) { unsigned long index =

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值