现在我总是听说二进制搜索树比随机选择的数据更快地构建,而不是有序数据,因为有序数据需要显式重新平衡以保持树高最小.
最近我实现了一个不可变的treap,一种特殊的二叉搜索树,它使用随机化来保持自己相对平衡.与我的预期相反,我发现我可以持续建立一个快速约2倍的treap,并且通常比有序数据更好地平衡 - 而且我不知道为什么.
这是我的treap实现:
这是一个测试程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static Random rnd = new Random();
const int ITERATION_COUNT = 20;
static void Main(string[] args)
{
List<double> rndTimes = new List<double>();
List<double> orderedTimes = new List<double>();
rndTimes.Add(TimeIt(50, RandomInsert));
rndTimes.Add(TimeIt(100, RandomInsert));
rndTimes.Add(TimeIt(200, RandomInsert));
rndTimes.Add(TimeIt(400, RandomInsert));
rndTimes.Add(TimeIt(800, RandomInsert));
rndTimes.Add(TimeIt(1000, RandomInsert));
rndTimes.Add(TimeIt(2000, RandomInsert));
rndTimes.Add(TimeIt(4000, RandomInsert));
rndTimes.Add(TimeIt(8000, RandomInsert));
rndTimes.Add(TimeIt(16000, RandomInsert));
rndTimes.Add(TimeIt(32000, RandomInsert));
rndTimes.Add(TimeIt(64000, RandomInsert));
rndTimes.Add(TimeIt(128000, RandomInsert));
string rndTimesAsString = string.Join("\n", rndTimes.Select(x …Run Code Online (Sandbox Code Playgroud) 如何在Windows上安装APC?我使用的是PHP 5.3,Windows 7 x64.
我用了
pecl install apc
Run Code Online (Sandbox Code Playgroud)
我有
C:\PHP>pecl install apc
downloading APC-3.0.19.tgz ...
Starting to download APC-3.0.19.tgz (115,735 bytes) ............
done: 115,735 bytes 47 source files, building
WARNING: php_bin c:\php\php.exe appears to have a suffix \php.exe, but config
variable php_suffix does not match running: msdev APC.dsp /MAKE "APC - Release"
ERROR: Did not understand the completion status returned from msdev.exe.
Run Code Online (Sandbox Code Playgroud) 我在本地计算机上安装了Rails 2.3.4和Rails 3.0.0.beta.我在一个独立的ruby脚本中使用ActiveRecord,当我执行require 'active_record'3.0.0.beta加载时.我如何强迫它要求2.3.4呢?(不卸载3.0.0.beta)
我有一块成熟的地理空间软件,最近重新编写了一些区域,以便更好地利用现代PC中的多处理器.具体来说,显示,GUI,空间搜索和主要处理都被分离出来以分离线程.该软件具有相当大的GUI自动化套件,用于功能回归,另一个较小的用于性能回归.虽然所有自动化测试都已通过,但我并不相信它们能够提供足够的覆盖范围来查找与多线程相关的竞争条件,死锁和其他恶意相关的错误.您将使用哪些技术来查看是否存在此类错误?假设有一些技术可以根除,那么你会提倡哪些技术可以根除它们?
我到目前为止所做的是在调试器下运行的应用程序上运行GUI功能自动化,这样我就可以摆脱死锁并捕获崩溃,并计划进行边界检查器构建并针对该版本重复测试.我还通过PC-Lint对源进行了静态分析,希望找到潜在的死锁,但没有任何有价值的结果.
该应用程序是C++,MFC,多文档/视图,每个文档有许多线程.我使用的锁定机构是基于一个对象,它包括一个指针指向一个CMutex,其被锁定在构造函数和在析构函数释放上.我使用此对象的局部变量来根据需要锁定各种代码,并且我的互斥锁有一个超时,如果达到超时,则会触发警告.尽可能使用资源副本,尽可能避免锁定.
您还会进行哪些其他测试?
编辑:我已经在许多不同的测试和编程论坛上发布了这个问题,因为我很想知道不同的思维方式和思想流派如何解决这个问题.如果你看到它在其他地方交叉发布,那么道歉.我会在一周左右后提供回复的摘要链接
我希望方面基于如下条件退出方法调用:
[AttributeUsage(AttributeTargets.Method)]
public class IgnoreIfInactiveAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
if (condition)
{
**// How can I make the method return here?**
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢.
我试图找出如何定义影响特定路径下所有文件的autocmd.
我试过的autocmd是这样的
autocmd BufNewFile,BufRead /specificPath/** imap <buffer> ....
Run Code Online (Sandbox Code Playgroud)
现在,如果我编辑了/foo/bar/specificPath/baz/something/bla.txt,我希望使用这个autocmd,但如果我编辑了/ foo/bar/here /和/ there/moreBla则不行.文本
如果我开始将vim放在特定路径"上面"的目录中,这可以按照我的意愿运行.但如果我低于该目录,则不会.显然,autocmd的模式与相对文件名匹配,而不是绝对名称.
我有许多正在执行长期任务的线程。这些线程本身具有子线程,这些子线程会进一步细分工作。我跟踪以下内容的最佳方法是什么:
我想以一种尽可能高效的方式做到这一点,并且一旦线程完成,由于我需要尽早释放内存,我不希望对它们有任何引用。
有什么建议吗?
我可以使用HttpUrlConnection建立连接.我的代码如下.
client = new DefaultHttpClient();
URL action_url = new URL(actionUrl);
conn = (HttpURLConnection) action_url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("userType", "2");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestMethod(HttpPost.METHOD_NAME);
DataOutputStream ds = new DataOutputStream(conn.getOutputStream());
String content = "username=username1&password=password11";
Log.v(TAG, "content: " + content);
ds.writeBytes(content);
ds.flush();
ds.close();
InputStream in = conn.getInputStream();//**getting filenotfound exception here.**
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder str1 = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str1.append(line);
Log.v(TAG, "line:" + line);
}
in.close();
s = str1.toString();
Run Code Online (Sandbox Code Playgroud)
获取filenotfound异常.不知道为什么?
否则给我一些建议,通过代码将用户名和密码链接参数传递给网址.
我最近下载了IMDbpy模块..当我这样做时,
import imdb
help(imdb)
Run Code Online (Sandbox Code Playgroud)
我没有得到完整的文档..我必须这样做
im = imdb.IMDb()
help(im)
Run Code Online (Sandbox Code Playgroud)
查看可用的方法.我不喜欢这个控制台界面.有没有更好的阅读文档的方法.我是指在一个页面中与模块imdb相关的所有文档..
嗨,我正在尝试将原始机器代码加载到内存中并在C程序中运行它,现在当程序执行时,它试图在内存上运行mprotect使其可执行时中断.我也不完全确定如果内存设置正确,它将执行.我目前在Ubuntu Linux x86上运行它(也许问题是Ubuntu的过度保护?)
我目前拥有以下内容:
#include <memory.h>
#include <sys/mman.h>
#include <stdio.h>
int main ( int argc, char **argv )
{
FILE *fp;
int sz = 0;
char *membuf;
int output = 0;
fp = fopen(argv[1],"rb");
if(fp == NULL)
{
printf("Failed to open file, aborting!\n");
exit(1);
}
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
membuf = (char *)malloc(sz*sizeof(char));
if(membuf == NULL)
{
printf("Failed to allocate memory, aborting!\n");
exit(1);
}
memset(membuf, 0x90, sz*sizeof(char));
if( mprotect(membuf, sz*sizeof(char), PROT_EXEC | PROT_READ | PROT_WRITE) …Run Code Online (Sandbox Code Playgroud)