• 大小: 1.73MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-24
  • 语言: 其他
  • 标签:

资源简介

币圈的撮合系统,高并发,使用了字典哈希表,以及跳跃表进行撮合。

资源截图

代码片段和文件信息

/*
 * Description: 
 *     History: yang@haipo.me 2017/03/15 create
 */

# include “me_config.h“
# include “me_balance.h“

dict_t *dict_balance;
static dict_t *dict_asset;

struct asset_type {
    int prec_save;
    int prec_show;
};

static uint32_t asset_dict_hash_function(const void *key)
{
    return dict_generic_hash_function(key strlen(key));
}

static void *asset_dict_key_dup(const void *key)
{
    return strdup(key);
}

static void *asset_dict_val_dup(const void *val)
{
    struct asset_type *obj = malloc(sizeof(struct asset_type));
    if (obj == NULL)
        return NULL;
    memcpy(obj val sizeof(struct asset_type));
    return obj;
}

static int asset_dict_key_compare(const void *key1 const void *key2)
{
    return strcmp(key1 key2);
}

static void asset_dict_key_free(void *key)
{
    free(key);
}

static void asset_dict_val_free(void *val)
{
    free(val);
}

static uint32_t balance_dict_hash_function(const void *key)
{
    return dict_generic_hash_function(key sizeof(struct balance_key));
}

static void *balance_dict_key_dup(const void *key)
{
    struct balance_key *obj = malloc(sizeof(struct balance_key));
    if (obj == NULL)
        return NULL;
    memcpy(obj key sizeof(struct balance_key));
    return obj;
}

static void *balance_dict_val_dup(const void *val)
{
    return mpd_qncopy(val);
}

static int balance_dict_key_compare(const void *key1 const void *key2)
{
    return memcmp(key1 key2 sizeof(struct balance_key));
}

static void balance_dict_key_free(void *key)
{
    free(key);
}

static void balance_dict_val_free(void *val)
{
    mpd_del(val);
}

static int init_dict(void)
{
    dict_types type;
    memset(&type 0 sizeof(type));
    type.hash_function  = asset_dict_hash_function;
    type.key_compare    = asset_dict_key_compare;
    type.key_dup        = asset_dict_key_dup;
    type.key_destructor = asset_dict_key_free;
    type.val_dup        = asset_dict_val_dup;
    type.val_destructor = asset_dict_val_free;

    dict_asset = dict_create(&type 64);
    if (dict_asset == NULL)
        return -__LINE__;

    memset(&type 0 sizeof(type));
    type.hash_function  = balance_dict_hash_function;
    type.key_compare    = balance_dict_key_compare;
    type.key_dup        = balance_dict_key_dup;
    type.key_destructor = balance_dict_key_free;
    type.val_dup        = balance_dict_val_dup;
    type.val_destructor = balance_dict_val_free;

    dict_balance = dict_create(&type 64);
    if (dict_balance == NULL)
        return -__LINE__;

    return 0;
}

int init_balance()
{
    ERR_RET(init_dict());

    for (size_t i = 0; i < settings.asset_num; ++i) {
        struct asset_type type;
        type.prec_save = settings.assets[i].prec_save;
        type.prec_show = settings.assets[i].prec_show;
        if (dict_add(dict_asset settings.assets[i].name &type) == NULL)
            return -__LINE__;
    }

    return 0;
}

static struct asset_type *get_asset_type(const char *asset)
{
    dict_entry *entry = dict_

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3622  2018-05-23 15:00  matchengine\config.json

     文件        365  2018-05-23 15:00  matchengine\makefile

     文件    5937072  2018-05-23 15:00  matchengine\matchengine.exe

     文件       9353  2018-05-23 15:00  matchengine\me_balance.c

     文件       1284  2018-05-23 15:00  matchengine\me_balance.h

     文件      29752  2018-05-23 15:00  matchengine\me_balance.o

     文件       5960  2018-05-23 15:00  matchengine\me_cli.c

     文件        146  2018-05-23 15:00  matchengine\me_cli.h

     文件      30080  2018-05-23 15:00  matchengine\me_cli.o

     文件       5410  2018-05-23 15:00  matchengine\me_config.c

     文件       2098  2018-05-23 15:00  matchengine\me_config.h

     文件      20480  2018-05-23 15:00  matchengine\me_config.o

     文件       6745  2018-05-23 15:00  matchengine\me_dump.c

     文件        317  2018-06-15 09:51  matchengine\me_dump.h

     文件      46328  2018-05-23 15:00  matchengine\me_dump.o

     文件      11026  2018-05-23 15:00  matchengine\me_history.c

     文件        637  2018-05-23 15:00  matchengine\me_history.h

     文件      53360  2018-05-23 15:00  matchengine\me_history.o

     文件      14171  2018-05-23 15:00  matchengine\me_load.c

     文件        393  2018-05-23 15:00  matchengine\me_load.h

     文件      52248  2018-05-23 15:00  matchengine\me_load.o

     文件       3634  2018-05-23 15:00  matchengine\me_main.c

     文件      23640  2018-05-23 15:00  matchengine\me_main.o

     文件      36156  2018-05-23 15:00  matchengine\me_market.c

     文件       1952  2018-05-23 15:00  matchengine\me_market.h

     文件      68440  2018-05-23 15:00  matchengine\me_market.o

     文件       7953  2018-05-23 15:00  matchengine\me_message.c

     文件        786  2018-05-23 15:00  matchengine\me_message.h

     文件      47408  2018-05-23 15:00  matchengine\me_message.o

     文件       4447  2018-05-23 15:00  matchengine\me_operlog.c

............此处省略19个文件信息

评论

共有 条评论

相关资源