我想编写一个程序来测试两个文件是否重复(具有完全相同的内容).首先,我测试文件是否具有相同的大小,如果我们开始比较它们的内容.
我的第一个想法是将文件"拆分"为固定大小的块,然后为每个块启动一个线程,fseek启动每个块的启动字符并继续并行比较.当一个线程的比较失败时,其他工作线程被取消,程序退出线程产生循环.
代码如下所示: dupf.h
#ifndef __NM__DUPF__H__
#define __NM__DUPF__H__
#define NUM_THREADS 15
#define BLOCK_SIZE 8192
/* Thread argument structure */
struct thread_arg_s {
const char *name_f1; /* First file name */
const char *name_f2; /* Second file name */
int cursor; /* Where to seek in the file */
};
typedef struct thread_arg_s thread_arg;
/**
* 'arg' is of type thread_arg.
* Checks if the specified file blocks are
* duplicates.
*/
void *check_block_dup(void *arg);
/**
* Checks if two files …Run Code Online (Sandbox Code Playgroud) 为什么此代码注释有效(代码编译并运行正常,但实际上并未显示排列):
int main(int argc, char *argv[])
{
long number;
vector<long> interval;
vector<long>::const_iterator it;
cout << "Enter number: ";
cin >> number;
while(number-->0){
interval.push_back(number);
}
do{
for(it = interval.begin(); it < interval.end(); ++it){
cout << *it << " ";
}
cout << endl;
} while(next_permutation(interval.begin(), interval.end()));
return (0);
}
Run Code Online (Sandbox Code Playgroud)
但改变这一行后:
while(next_permutation(interval.begin(), interval.end()));
Run Code Online (Sandbox Code Playgroud)
有:
while(prev_permutation(interval.begin(), interval.end()));
Run Code Online (Sandbox Code Playgroud)
不是排列通过作用于位置来改变向量中的元素吗?
PS:我现在编辑了代码.
场景:
sqlldr(SQL Loader),我必须创建一个包含CSV中所有数据的临时表.您如何建议进行所有这些处理,以便我不会影响生产环境的整体性能?
(注意:我不应该预先处理.csv).
任何建议将受到高度赞赏!
我在玩 antlr4 语法文件,我想编写自己的jsonpath语法。
我想出了这个:
grammar ObjectPath;
objectPath : dnot;
dnot : ROOT expr ('.' expr)
| EOF
;
expr : select #selectExpr
| ID #idExpr
;
select : ID '[]' #selectAll
| ID '[' INT ']' #selectIndex
| ID '[' INT (',' INT)* ']' #selectIndexes
| ID '[' INT ':' INT ']' #selectRange
| ID '[' INT ':]' #selectFrom
| ID '[:' INT ']' #selectUntil
| ID '[-' INT ':]' #selectLast
| ID '[?(' query ')]' #selectQuery
; …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的二叉树结构,如:
struct nmbintree_s {
unsigned int size;
int (*cmp)(const void *e1, const void *e2);
void (*destructor)(void *data);
nmbintree_node *root;
};
struct nmbintree_node_s {
void *data;
struct nmbintree_node_s *right;
struct nmbintree_node_s *left;
};
Run Code Online (Sandbox Code Playgroud)
有时我需要从另一个树中提取"树",我需要获取"提取的树"的大小,以便更新初始"树"的大小.
我在考虑两种方法:
1)使用递归函数,如:
unsigned int nmbintree_size(struct nmbintree_node* node) {
if (node==NULL) {
return(0);
}
return( nmbintree_size(node->left) + nmbintree_size(node->right) + 1 );
}
Run Code Online (Sandbox Code Playgroud)
2)以迭代方式(使用堆栈/队列)+对节点进行计数的预订/顺序/后序遍历.
你认为什么方法更像是"记忆失败证明"/表现?
还有其他建议/提示吗?
注意:我可能会在将来对我的小项目使用此实现.所以我不想意外失败:).
您好我在C中编写了一些数据结构,并且我意识到它们的相关函数不是线程安全的.我正在编写代码只使用标准C,我想实现某种"同步".
我当时想做这样的事情:
enum sync_e { TRUE, FALSE };
typedef enum sync_e sync;
struct list_s {
//Other stuff
struct list_node_s *head;
struct list_node_s *tail;
enum sync_e locked;
};
typedef struct list_s list;
Run Code Online (Sandbox Code Playgroud)
,在列表结构中包含一个"布尔"字段,表示结构状态:已锁定,未锁定.
例如,插入函数将以这种方式重写:
int list_insert_next(list* l, list_node *e, int x){
while(l->locked == TRUE){
/* Wait */
}
l->locked = TRUE;
/* Insert element */
/* -------------- */
l->locked = FALSE;
return (0);
}
Run Code Online (Sandbox Code Playgroud)
在列表上操作时,"锁定"字段将设置为TRUE,不允许任何其他更改.操作完成后,"锁定"字段将再次设置为"TRUE".
这种做法好吗?您是否了解其他方法(仅使用标准 C).
我必须编写一个返回pxdiv 的当前大小(in )的javascript函数.不幸的是,div的重量是指定%而不是px.
div的风格: position: absolute; width: 100%; height: 100%;
我的宽度返回功能:
function getTableWidth(tableId){
var tabWidth = document.getElementById('pt1::tabb').children[0].children[0].style.width;
return tabWidth;
}
Run Code Online (Sandbox Code Playgroud)
tabWidth 是'100%'.
是否可以返回px宽度而不是%宽度?
注意:我无法访问任何html/css,因为我正在处理的页面是通过复杂的框架生成的.我只能嵌入javascript.
我想为我的应用程序编写一个默认的Logger.目前我使用的是默认的Java API类记录器.
我想知道是否可以格式化我的日志看起来像这样:
[level] [dd:MM:YYYY] [hh:mm:ss] message
Run Code Online (Sandbox Code Playgroud)
记录器还应该能够将消息打印到System.out和文件中吗?我应该在哪里寻找这个功能?你能给我一些代码片段吗?
给出以下代码(它是一个为列表数据结构生成代码的宏,基于所包含的类型).
list.h
#ifndef _LIST_H
#define _LIST_H
#ifdef __cplusplus
extern "C" {
#endif
#define LIST_TEMPLATE_INIT(type) \
typedef struct __list_s_##type { \
struct __list_s_##type *next; \
type value; \
} __list_##type; \
\
__list_##type * __list_##type##_malloc(type value){ \
__list_##type * list = NULL; \
list = malloc(sizeof(*list)); \
list->value = value; \
return list; \
}\
\
void __list_##type##_free(__list_##type *list){\
__list_##type * back = list;\
while(list=list->next){\
free(back);\
back = list;\
}\
}
#define LIST_TYPE(type) __list_##type
#define LIST_MALLOC(type,value) __list_##type##_malloc(value)
#define LIST_FREE(type,list) __list_##type##_free(list)
#define …Run Code Online (Sandbox Code Playgroud) 使用ORACLE SQL.
我有一个表' Employees'有一个属性' hire_date'.我的任务(书籍练习)是写一个SELECT能告诉我1995年,1996年,1997年和1998年雇用了多少员工的任务.
就像是:
TOTAL 1995 1996 1997 1998
-----------------------------------------
20 4 5 29 2
Run Code Online (Sandbox Code Playgroud)
单独计算每年的员工数量,例如:
SELECT
COUNT(*),
FROM
employees e
WHERE
e.hire_date like '%95'
Run Code Online (Sandbox Code Playgroud)
但是当我必须以所需格式"聚合"数据时,我遇到了困难.有什么建议 ?