??xml version="1.0" encoding="utf-8" standalone="yes"?>AV色综合久久天堂AV色综合在,精品久久久久中文字幕一区,亚洲综合伊人久久综合http://www.shnenglu.com/xiaoluoluo/zh-cnThu, 08 May 2025 17:18:35 GMTThu, 08 May 2025 17:18:35 GMT60散列3http://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102070.html罗|?/dc:creator>罗|?/author>Fri, 27 Nov 2009 09:14:00 GMThttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102070.htmlhttp://www.shnenglu.com/xiaoluoluo/comments/102070.htmlhttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102070.html#Feedback7http://www.shnenglu.com/xiaoluoluo/comments/commentRss/102070.htmlhttp://www.shnenglu.com/xiaoluoluo/services/trackbacks/102070.html  散列q是最后一章了Q快毕业了,q几天赶快把论文写完Q到回家q不C个月Q答应张老师再去实验室把做的东西ȝ一下,其实打算在实验室再呆两个月,腊月底再回,惛_的东西嘛Q我想研I一下opencv的内存管理机Ӟl合我买的那本Applied C++,Z推销一下这本书Q这本书很薄Q两癑֤,介绍如何应用c++来解军_发商业Y件时所固有的问题,最难能可贵的是Q从头至提供了一个图像处理框Ӟ对于惛_数字囑փ处理Q机器视觉方向深入探IӞ不是具体法Q而是整个软g架构Q有挺大的启发意义的(虽然|上评h不是太好Q可能比较牛的h看不上吧Q也有可能这本书比较偏重于数字图像领?Q还惛_的东西呢Q年前和q后几个月的旉Bjarne Stroustrup的那本c++,Mark Allen Weiss的那本数据结构,Jon Kleinberg 的那本算法设计,后两本书是俺在图像室的图书角扑ֈ的,非常的不错哦Q可惜毕业前pq,正好督促我赶紧看Q在联合书城看到Richard Johnsonbaugh的Discrete Mathematics,竟然是第七版了,只能怪我资质太差看不懂knuth的那三本圣经Q只好咬着牙买下来先琢琢了是打基了,公司有项目做嵌入式^C的编译器Q要是有旉的话看看嵌入式操作系l和~译原理吧,很想写个~译器,q么多好书要看,有时候真不想回家q年了,嘿嘿Q说着玩的Q到时候家里肯定杀猪了Q不回去真是太可惜了?br>
1.再散?br>   其实是前两中有提到的rehash了,对于使用qx探测的开攑֮制散列法Q如果表的元素填得太满,那么操作的运行时间将开始消耗过长,且插入操作可能失败。这可能发生在有太多删除和插入؜合的场合。此Ӟ一个解x法是建立另外一个大U两倍大的表(而且使用一个相关的新散列函?Q扫描整个原始散列表Q计每?未删除的)元素的新散列值ƈ其插入到新表中。整个操作成为再散列(rehashing)。这昄是一U非常昂늚操作Q其q行旉为O(N),因ؓ有N个元素要再散列而且表的大小Uؓ2NQ不q,因ؓ不是l常发生Q所以实际效果ƈ没有q么差。特别是Q在最后的再散列之前已l存在N/2ơ插入,因此d到每个插入上的花费基本是一个常数开销。如果这U数据结构是E序的一部分Q那么其影响是不明显的。另一斚wQ如果再散列作ؓ交互pȝ一部分q行Q那么其插入引v再散列的用户会感到速度减慢?br>    再散列可以用qx预测以多U方法实现。一U做法是只要表满一半就再散列。另一U极端的Ҏ是只有当插入p|时才再散列。第三种Ҏ即途中(middle-of-the-road){略Q当表到达某一个装填因子时q行再散列。由于随着装填因子的增加,表的性能的确在下降,因此Q以好的截至点实现的W三U策略,可能是最好的{略?br>
 1//Ҏ散列表和分链接散列表的再散列
 2void rehash()
 3{
 4    vector<HashEntry> oldArray = array;
 5    array.resize( nextPrime( 2* oldArray.size() ) );
 6    forint j = 0; j<array.size(); j++ )
 7        array[j].info = EMPTY;
 8    currentSize = 0;
 9    forint i = 0; i<oldArray.size(); i++ )
10        if( oldArray[i].info == ACTIVE )
11            insert( oldArray[i].element );
12}

13
14void rehash()
15{
16    vector<list<HashedObj> > oldLists = theLists;
17    theLists.resize( nextPrime( 2* theLists.size() ) );
18    forint j = 0; j<theLists.size(); j++ )
19        theLists[j].clear();
20    currentSize = 0;
21    forint i = 0; i<oldLists.size(); i++ )
22    {
23        list<HashedObj>::iterator itr = OldLists[i].begin();
24        while ( itr != oldLists[i].end() )
25            insert( *itr++ );
26    }

27}


2.标准库中的散列表
    标准库中不包括set和map的散列表实现。但是,许多的编译器提供h与set和mapcȝ同的成员函数的hash_set和hash_map.
    要用hash_set和hash_mapQ就必须有相应的包含指oQ而且Q可能也需要相应的命名I间。这两者都是和~译器相关的。接下来q必L供相应的cd参数来说?br>hash_set和hash_map。对于hash_mapQ这些类型参数包括键的类型,值的cdQ散列函?q回无符h?和一个相{性操作符。遗憄是,至于键和值的cd参数如何
表示q是~译器相关的?br>    下一ơc++的较大的修订不可避免地包括q些hash_set和hash_map中的一个?br>
3.可扩散列
    最后讨论数据量太大以至于装不进d的情况,此时主要考虑的是索数据所需的磁盘存取次数。假讑֜L时刻都有N个记录要存储QN的值随旉而变化。此外,最多可把M个记录放入一个磁盘区块,设M=4,如果使用探测散列或分链接散列,那么主要的问题在于,即是理惛_布的散列表,在一ơ查找操作中Q冲H也可能引v对多个区块的讉K。不仅如此,当表变得q慢的时候,必须执行代h巨大的再散列q一步,它需要O(N)的磁盘访问?br>    一U聪明的选择成ؓ可扩散列(extendible hashing),它允许用两次盘讉K执行一ơ查找。插入操作也需要很的盘讉K.
   Extendible hashing from Wikipedia
   Extendible hashing
is a type of hash system which treats a hash as a bit string, and uses a trie for bucket lookup. Because of the hierarchal nature of the system, re-hashing is an incremental operation (done one bucket at a time, as needed). This means that time-sensitive applications are less affected by table growth than by standard full-table rehashes.

   

This is a more simplistic example from Fagin et al. (1979).

Assume that the hash function h(k) returns a binary number. The first i bits of each string will be used as indices to figure out where they will go in the "directory" (hash table). Additionally, i is the smallest number such that the first i bits of all keys are different.

Keys to be used:

h(k1) = 100100
h(k2) = 010110
h(k3) = 110110

Let's assume that for this particular example, the bucket size is 1. The first two keys to be inserted, k1 and k2, can be distinguished by the most significant bit, and would be inserted into the table as follows:

 directory
---------
|    0    |-----------> Bucket A (contains k2)
|---------|
|    1    |-----------> Bucket B (contains k1)
---------

Now, if k3 were to be hashed to the table, it wouldn't be enough to distinguish all three keys by one bit (because k3 and k1 have 1 as their leftmost bit. Also, because the bucket size is one, the table would overflow. Because comparing the first two most significant bits would give each key a unique location, the directory size is doubled as follows:

  directory
----------
|    00    |-----\
|----------|      ----------> Bucket A (contains k2)
|    01    |-----/
|----------|
|    10    |-----------> Bucket B (contains k1)
|----------|
|    11    |-----------> Bucket C (contains k3)
----------

And so now k1 and k3 have a unique location, being distinguished by the first two leftmost bits. Because k2 is in the top half of the table, both 00 and 01 point to it because there is no other key to compare to that begins with a 0.

4.结
    散列表可以用来以常数q_旉实现insert和contains操作。当使用散列表时Q注意诸如装填因子这Ll节是特别重要的Q否则时间界不再有效。当键不是短字符串或整数Ӟ仔细选择散列函数也是很重要的?br>    对于分离链接散列法,虽然装弹因子不大时性能q不明显降低Q但装填因子q是应该接近?Q对于探散列,除非完全不可避免Q否则装填因子不应该过0.5Q如果用线性探,那么性能随着装填因子接近?而急速下降。再散列q算可以通过使表增长(或收~?来实玎ͼq样可以保持合理的装填因子。对于空间紧~ƈ且不可能声明巨大散列表的情况Q这是很重要的?br>    二叉查找树也可以用来实现insert和contains操作。虽然^均时间界为O(logN)Q但是二叉查找树也支持那些需要排序的例程Q从而功能更强大Q用散列表不可能找出最元素。除非准知道一个字W串Q否则散列表也不可能有效地查扑֮。二叉查找树可以q速找C定范围内的所有项Q散列表却做不到。不仅如此,因ؓ查找树不需要乘法和除法QO(logN)q个旉界也不必比O(1)大那么多?br>    另一斚wQ散列的最坏情形一般来自于实现错误Q而有序的输入却可能二叉树运行得很差。^衡查找树实现的代L当高。因此,如果不需要排序的信息或者不定输入是否已经排序Q那么就应该选择散列q种数据l构?br>    散列的应用很qѝ编译器使用散列表跟t源代码中声明的变量Q这U数据结构叫做符可(symbol table)。散列表时这U问题的理想选择。标识符一般都不长Q因此散列函数能够迅速完成运。此外,按字母顺序排序变量通常也是不必要的?br>    散列表适用于Q何其节点有实名而不是数字名的图论问题。这里,当输入被d的时候,定点则按照它们出现的序?开始指定ؓ一些整数。再有,输入很可能有一l按字母序排列的项。例如,点可以是计机。此Ӟ如果一个特定的计算中心把它的计机列表成ibm1,ibm2,ibm3...那么Q若使用查找树则在效率方面很可能会有戏剧性的l果?br>   散列表的W三U常见的用途实在ؓ游戏~制的程序中。当E序搜烦游戏的不同的q动路径Ӟ它通过计算Z位置的散列函数而跟t一些已知的位置(q把对于该位|的Ud存储h)。如果同L位置再次出现Q程序通常通过单的Ud变换来避免昂늚重复计算。游戏程序的q种一般特点叫做置换表(transposition tableQ?
   散列的另一个用途是在线拼写查程序。如果拼写检查程序的主要功能是检查拼写错?而非U正错误),那么可以预先整个词典进行散列,q样可以在常数旉内检查单词拼写。散列表很适合q项工作Q因Z字母序排列单词q不重要Q而以它们在文件中出现的顺序显C错误拼写当然也是可以接受的?/span>


]]>
老外谈future of c++http://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102021.html罗|?/dc:creator>罗|?/author>Thu, 26 Nov 2009 16:23:00 GMThttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102021.htmlhttp://www.shnenglu.com/xiaoluoluo/comments/102021.htmlhttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/27/102021.html#Feedback2http://www.shnenglu.com/xiaoluoluo/comments/commentRss/102021.htmlhttp://www.shnenglu.com/xiaoluoluo/services/trackbacks/102021.html    又去Bartosz的c++ in action论坛上{了{Q看C个老外问Bartosz哥哥future of c++的帖?论坛比较hQ没有c++er和javaer们的互相炮蘪QBartosz有意思的是没忘记向各位推销他的D语言。。?br> 

helmi:

Hi, I just found this very useful site and I have read almost all of tutorial, guide, articles. smile.gif

I just ask everybody opinion on the future of C/C++ because a lot of other programming language out there now days. What do you think since more applications develop as on web base platform? This is just my observation in my country. I really like coding in C++ because I can feel I'm doing low level programming. I do have write game using directX as a hobby but to sustain, I have need to write applications using php, asp .net and jsp.


ps: Sorry for my bad English.

BartoszQ?/strong>
I see programming tasks as a pyramid. The base of the pyramid is formed by small tasks that don't require sophisticated languages or tools. That's where most of the programming is done. The top of the pyramid are tough tasks that just can't be done using Java or C#. Right now the language at the top is C++. There aren't very many complex tasks, so the top of the pyramid is rather narrow, but then the number of seasoned C++ programmers is also relatively small. In the United States, C++ programmers are in high demand (and are very well paid).

Will C++ keep its top position? I don't know. There are very many aspects of C++ that are very unsatisfactory. I am now involved in the development of the D language (http://digitalmars.com/d/), which has a chance of replacing C++.

helmi:
"the number of seasoned C++ programmers is also relatively small. In the United States, C++ programmers are in high demand (and are very well paid)."

Really? I should go working in the United States smile.gif


I have read of about the D language in a game forum. It's has a lot of features and so powerful but still need improvement, good IDE etc.

BartoszQ?/strong>
QUOTE (helmi @ Feb 1 2007, 05:30 PM) *
I have read of about the D language in a game forum. It's has a lot of features and so powerful but still need improvement, good IDE etc.

That's right. It needs an IDE, tools, and libraries. But it has a good chance of acqiring them quickly.

peter:
QUOTE (Bartosz @ Feb 2 2007, 04:32 AM) *
That's right. It needs an IDE, tools, and libraries. But it has a good chance of acqiring them quickly.


It would be great if there were a Visual Studio package for D smile.gif.

Unfortunately after trying to figure out how to do that by
browsing the Visual Studio SKD documentation and samples
for the last two days I finally gave up sad.gif.

There are two frameworks that are supposed to help
with the package development. One is written in C#
and the second is in C++ (depends heavily on Microsoft's ATL).
These are pretty heavy beasts and doesn't really
help if the developer doesn't get The Big Picture
(as I failed to get).

So, I tried to implement a package from scratch.

So far I get the IDE to show a new project type
and to call my implementation of the IVsProjectFactory
interface. When the IDE calls the
IVsProjectFactory::CreateProject I copy
the project template files into the new project
directory. Then I create an object implementating
the IVsProject3 and IVsHierarchy interfaces and
return it back to the IDE.
This is where I am stuck. Although the IDE then
calls some methods on the IVsProject3 and
IVsHierarchy interfaces, querying and setting
some properties. The IDE doesn't show the
new project node in the solution explorer.
There is only the topmost solution node
"Solution 'Project1' (1 Project)", nothing more.

And as I said before I was not able to figure out
what am I supposed to do after the project is created... sad.gif

~Peter

BartoszQ?/strong>
The best resource in this kind of projects are Microsoft forums. Here's a thread about adding language services to VS
adding language services to VS , and here's a more comprehensive list . Without these forums I would have never been able to embed the internet browser control in Code Co-op.

Another-- maybe even more attractive--option is to write an extension to Eclipse. There's been some discussion about it in the D forum, but it doesn't look like there are many volunteers.

peter:
Speaking about the D Programming Language.

How does it handle source file dependencies?

If I have two files File1.d and File2.d
and File2.d imports File1, then when
File1.d changes both files must be
recompiled.

Is my assumption correct?

~Peter

Bartosz:
This is a functionality of "make", not the compiler. But if you mean: Should both files be recompiled?; the answer is, yes.

Note also that you can generate D interface files, .di, which speed up the import process. These too have to be recompiled whenever their correspondig D file changes.

peter:
(Maybe you could add a new forum section about "D Programming" :-)

I wonder how one implements resource ownership transfer semantic in D?

~Peter

Bartosz:
QUOTE (peter @ Feb 15 2007, 07:34 AM) *
(Maybe you could add a new forum section about "D Programming" :-)

I will do exactly that!

helmi:
It is a good idea.

James:
I hope none of you mind me butting in for just a second.

I am currently a student in high school and I am interested in computer science and programming. I am fluent (on an intermediate level) in PHP (HTML, XML, and some minor AJAX/JS included). I would say I have a decent understanding of general coding practice/syntax/what have you, so I am certainly not starting from scratch.

In terms of D, C++, C#, Java, etc., where should I be focusing my efforts? I know there really isn't a straight forward answer, but maybe some of you could offer your opinion. I'm not necessarily looking for something thats going to land me the biggest paycheck (although I would be interested in what you have to say on the subject), but more something that will give me a good background for future endeavors, whether or not it be a new language.

I'm not sure if I can really go wrong, but I am just trying to find something that might suit me the best. I am not setting out to make anything in particular, like games or stuff along those lines. As said, I am just interest in furthering my understanding and setting myself up for down the road. Any tips you can offer me would be great.

Thanks

James

Bartosz:
QUOTE (James @ Feb 20 2007, 02:02 PM) *
In terms of D, C++, C#, Java, etc., where should I be focusing my efforts?
These languages have very similar structure, so my suggestion would be to learn them all. In order of difficulty, from easiest to hardest:
- Java
- C#
- D
- C++
Specializing in one single language not only pidgenholes you as a developer, but also prevents you from learning different programming styles.
James:
Thanks. I appreciate the reply.

Dave:
I've programming in Java, C#, C++ and many other languages over many years.

I've never seen any commercial demand for D so that may well be a stumbling point. I would look very closely at what happened to Borland/CodeGear. Of course alot of unix based open source languages have done well so maybe i'm wrong.

Bjarne is working on his next version of C++ called C++ 0x, I doubt even this will get traction in many places.

Assembler, C and C++ were general purpose system level languages, things have moved on now, sure they are still valid for development of the OS, drivers, performance and memory footprint critical software, but they do not support many of the higher level primitives business software and web developers want.

Most programmers in the world however don't work on the large volume projects where the increased development costs can be amortised. They work on custom in house solutions to business problems, this is why we have Java and C#, they are the modern equivalent of Smalltalk that is now feasible due to vast hardware resources. These projects generally last only a few years before a rewrite making developer cost a large factor, and hardware cost fairly insignificant.

I would therefore strongly advise most people to learn at least one high level language to go with their lower level languages in order to have a successful career. Its unfortunate alot of the old skills are being lost in assembler, compiler design etc. I would still certainly reccomend most new students learning C# or Java over C/C++ or D as their first language.

Eclipse is an excellent open source IDE, It already supports multiple languages, and runs on multiple OS's it might be a better bet for D than Visual Studio.

ivec:
QUOTE (Dave @ Aug 23 2007, 12:25 PM) *
Bjarne is working on his next version of C++ called C++ 0x, I doubt even this will get traction in many places.


This is just so inaccurate that I have to clarify:
This is not about "Bjarne working on his next version of his language".
It is the ISO C++ standard committee working on the next revision of the standard C++ language. This is a collaborative and active process, as can be seen at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ .

When the standard is adopted (expected in a couple of years), you can be certain that all vendors of C++ compilers will be implementing the features introduced in the new standard. I am very confident that the new standard will have no problem getting traction wherever C++ remains relevant.

--------------------

Bartosz:
Yes, a lot of bright people work on the development of C++, not only in the Standards Committee; and I expect C++ 0x to introduce a lot of great features.

There are however some aspects of language development that are not reachable from the current state of C++, because of backwards compatibility. That's where D will shine. Version 2.0 of D is expected about the same time as C++ 0x-- meaning, before 2010. (The 0x stands for 200x--C++ is cutting it real close!).

As an example, D will unify templates and function templates--In D a function is just a fully specialized template.

hansgostajonsson:
Hello! As a hobby programmer I am hardly qualified to write here but: When I studied programming at university in 1987 I learnt pascal and loved it. It was said to be the future, but "for old times sake" we were also required to learn cobol and fortran - 2 languages then thought to be barely breathing. They seem , however, still to be hanging around, pascal is still in swing as Delphi but it was not so long after I learnt it said to be decrepit and I had to move on to c and then c++ if I wanted to move with the times. Then Java was the swinging language and so on to c#. Now D looms high on the horizon. It may seem a naive question but why can't d be implemented as a development of c++ - to an amateur it seems a look alike. hans jönsson

Bartosz:
If you look at the development of C++ over the years you'll notice that virtually every feature that's been added to the language stays with it, whether it made sense or not. If you imagine C as a fast but flimsy and dangerous ship, C++ grew layers and layers of barnacles over it, in the hope to strengthening it. Instead C++ has kept all the weaknesses of C at its core; plus it made if very difficult not only to master, but even to start learning.

The direction of D that I'm advocating is to make it as easy and safe for beginners as Java or C#. You should be able to use D productively without the need to understand pointers or memory management (D is garbage-collected). D has built in (and very efficient) arrays and strings. Classes are treated pretty much like in Java.

But unlike Java, D also offers all the sophisticated features of C++, except that they were desingned into the language from the start. Instead of layers of barnacles you have some well designed solid language architecture.

peter:
Personally, I don't believe that Yet Another Programming Language Based on C/C++, Java, etc. will make our coding and code maintaining life any easier. Programming languages evolved over 50 years yet I think the most radical step to writing more correct and more maintainable software was that from FORTRAN to ALGOL. From that point on any new language (from the ALGOL family) brings IMHO only very marginal improvements wrt. code maintainability and I don't think this will change in the future. Also after that 50 year of programming evolution and experience our best programming tool is still a simple text editor. I don't think this is right.

Presently, I'm slowly turning my attention to other programming paradigms. From them I see the Data Flow and Multi Agent paradigms most promising partly due to their great potential to exploit the future many-core processors. Also they lend themselves more easily to "diagrammatic" and/or visual programming than present day mainstream programming languages.

Just my ?.02

~Peter

P.S. I sometimes browse through the digitalmars.D newsserver and, frankly, based on most posts there the very LAST thing I'd say about the D programming language is: "well designed solid language architecture".

Also, I looked at the sources for the D compiler and the first immediate thought was: What programming language can design a person with such coding practices... I mean no offense to Walter Bright (I really admire his persistence and devotion to his creation), but those were just my feelings.

hansgostajonsson:
Thanks for replies. A few musings. A new language, like reorganizations, give new hope an generally we learn something in the process. I am a newly retired psychologist with old studies in computer science. Psychology differs from other sciences - it is one in many of it's fields - in that it has been founded a couple of times ( Gestalt psychology, functionalism, behaviourism) - not once like most other sciences. It seems to be the same for language development in computer science and you long for something like the explanation of dna when genetics became molecular biology and never has looked back again. Parhaps a futile dream. It seems that d is based on practical considerations rather than theoretical progress and therefore will be superseeded by the next language but not killed off. I think one problem is that new languages are not good enough to kill once and for all older languages. We will have a lot of not so good but good enough ones hanging around - the same in psychology. Just a few musings. Thanks for a very interesting site. greetings hans jönsson

Bartosz:
QUOTE (peter @ Mar 4 2008, 05:22 AM) *
Personally, I don't believe that Yet Another Programming Language Based on C/C++, Java, etc. will make our coding and code maintaining life any easier. Programming languages evolved over 50 years yet I think the most radical step to writing more correct and more maintainable software was that from FORTRAN to ALGOL. From that point on any new language (from the ALGOL family) brings IMHO only very marginal improvements wrt. code maintainability and I don't think this will change in the future.

A lot happend since ALGOL. Probably the biggest revolution was the introduction of the object oriented paradigm. OO programs are a lot more maintainable. In other areas progress was more quantitative than qualitative, but the accumulation of changes can make a lot of difference. Garbage collection, for instance, has entered the mainstream. So did functional programming techniques. There was also a shift of emphasis towards safe programming. Not to mention the latest revolution--multicore. Java bit the bullet by defining a memory model for parallel programming. C++ is working on it too.
QUOTE
Also after that 50 year of programming evolution and experience our best programming tool is still a simple text editor. I don't think this is right.
No, it's not right. Personally, I use Visual Studio in my C++ development. I also used Eclipse for Java. C++ has some of the worst development tools because it's such a hard language to parse. By the way, there is a D plugin for Eclipse. I didn't use it because it doesn't support D 2.0 yet.
QUOTE
Presently, I'm slowly turning my attention to other programming paradigms. From them I see the Data Flow and Multi Agent paradigms most promising partly due to their great potential to exploit the future many-core processors. Also they lend themselves more easily to "diagrammatic" and/or visual programming than present day mainstream programming languages.
These are all cool paradigms, but they are still far from the mainstream. My current interest is in Software Transactional Memory as the new paradigm for multicore programming.
QUOTE
P.S. I sometimes browse through the digitalmars.D newsserver and, frankly, based on most posts there the very LAST thing I'd say about the D programming language is: "well designed solid language architecture".
Point taken. Version 2.0 is still in flux. It might look like there is a lot of random experimenting, but there is solid theory behind most of it. In fact I'm pushing for updating the D manifesto to better explain the goals of the language. There is also a big difference between version 1.0 and 2.0. Version 1.0 was more of a "better C++". 2.0 is way beyond that.
QUOTE
Also, I looked at the sources for the D compiler and the first immediate thought was: What programming language can design a person with such coding practices... I mean no offense to Walter Bright (I really admire his persistence and devotion to his creation), but those were just my feelings.

Touche! What can I say, I'm not fond of Walter's programming style either wink.gif.

Bartosz:
QUOTE (hansgostajonsson @ Mar 4 2008, 12:51 PM) *
It seems that d is based on practical considerations rather than theoretical progress

Practical considerations make or break a language. There are some theoretically beautiful languages that nobody uses outside of the academia because they are not practical.

But there's also a lot of theoretical progress in computer science that is being incorporated into D.

Hossein:
QUOTE (Bartosz @ Mar 4 2008, 11:10 PM) *
But there's also a lot of theoretical progress in computer science that is being incorporated into D.


Wow! This is what amused me in the first place in fact! biggrin.gif OK, it seems that I can deny my extreme laziness here, and ask for this from you (Bartosz): Could you please give a list of all these nice features of D which attract us -- the snubish [wink.gif] people of Theoretical Computer Science of academia?

(And, BTW, like I mentioned in some other posting: People of academia wouldn't really like it that they don't publish proceedings in their D conferences...)

Cheers,
--Hossein

Bartosz:
We are trying to incorporate the latest PL trends in D, sometimes even before they mature wink.gif.

One major area is safe programming. There's been a lot of research into proving soundness of various languages using operational semantics. It culminated in the soundness proof for Featherweight (Generic) Java. Although it's not a goal of D to be a sound language (we do want pointers after all), we are defining a sound subset of D. In particular, we have a program that can translate Java programs into this subset. We will have one-to-one correspondence between Java semantics and the semantics of a subset of D (which is equivalent to having denotational semantics for the D subset).

We are planning on extending the safe D subset with other sound features, such as discriminated unions and elements of functional programming. D already supports anonymous functions and closures.

The other major area is concurrent programming. Again, Java leads the crowd with its memory model. D's memory model will most likely resemble that of C++ (still in the form of a proposal). The difference between the Java model and the C++ model is that Java gives some guarantees even for programs with race conditions-- C++ doesn't. So a racy program in C++ may exhibit undefined behavior. On the other hand Java has a virtual machine that may enforce a lot more during runtime that can be accomplished in a compiled language.

How can we support safe concurrency in the presence of races--or eliminate the races altogether? The idea is to build software transactional memory into D. Even though STM might not offer the best performance, it is much safer (and easier) than lock-based programming. Especially if we can build support for transactions into the type system, as has been done for Concurrent Haskell.

markm:
IDE for D use CodeBlocks, version 8.02 supports D.

http://www.codeblocks.org/














]]>
散列2http://www.shnenglu.com/xiaoluoluo/archive/2009/11/26/102001.html罗|?/dc:creator>罗|?/author>Thu, 26 Nov 2009 12:20:00 GMThttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/26/102001.htmlhttp://www.shnenglu.com/xiaoluoluo/comments/102001.htmlhttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/26/102001.html#Feedback0http://www.shnenglu.com/xiaoluoluo/comments/commentRss/102001.htmlhttp://www.shnenglu.com/xiaoluoluo/services/trackbacks/102001.html3 不用链表的散列?br>    分离链接散列法的缺Ҏ使用一些链表。由于给新单元分配地址需要时_因此q就D法的速度有些~慢Q同时算法实际上q要求第二种数据l构的实现。解军_H的另一个方法是当冲H发生时尝试选择另一个单元,直到扑ֈI的单元。更正式圎ͼ单元hi(x)=(hash(x)+f(i))mod TableSize,且f(0)=0.函数f是冲H解军_数。因为所有的数据都要|入表内Q所以用这个方案所需要的表要比分链接散列需要的表大。一般说来,对不使用分离链接法的散列表来_其装填因子应该低?#955;=0.5。我们称q样的表为探散列表(probing hash tables)?br>    (1)当f是i的线性函数时QؓU性探,一般情况下f(i)=iQ线性探容易在占据的单元Ş成一些区块,其结果成Zơ聚?primary clustering)?br>    (2)qx探测是消除线性探中一ơ聚集问题的冲突解决Ҏ。^Ҏ就是冲H函Cؓ二次函数的探方法。流行的选择是f(i)=i2.
               定理Q如果用^Ҏ,且表的大是素数Q那么当表至有一半是I的时候,总能够插入一个新的元素?br>        如果哪怕表有比一半多一个的位置被填满,那么插入都有可能p|(虽然q种可能性极?。另外,表的大小是素C非常重要。如果表的大不是素敎ͼ则备选单?br>        的个数可能会锐减。例如,若表的大是16Q那么备选单元只能在距散列?Q??q处?br>        在探散列表中标准的删除操作不能执行Q因为相应的单元可能已经引vq冲H,元素l过它存储在别处。因此,探测散列表需要懒惰删除?/span>
        实现探测散列表所需要的cL口在下图中给出。这里不使用链表数组Q而是使用散列表项单元数组。嵌套的cHashEntry存储在info成员中一个项的状态,q个状态可
        以是ACTIVE,EMPTY或DELETED?br>
   

 1//使用探测{略的散列表的类接口Q包括嵌套的HashEntry
 2  c?br> 3template <typename HashedObj>
 4class HashTable
 5{
 6public:
 7    explicit HashTable( int size = 101 );
 8    
 9    bool contains( const HashedObj &x ) const;
10    
11    void makeEmpty();
12    bool insert( const HashedObj &x );
13    bool remove( const HashedObj &x );
14    
15    emum EntryType (ACTIVE,EMPTY,DELETED );
16
17private:
18    struct HashEntry
19    {
20        HashedObj element;
21        EntryType info;
22        HashEntry( const HashedObj & e = HashedObj(), EntryType i = EMPTY ) : element(e), info(i) { }
23    }
;
24
25    vector<HashEntry> array;
26    int currentSize;
27 
28    bool isActive( int currentPos ) const;
29    int findPos( const HashedObj &x ) const;
30    void rehash();
31    int myhash( const HashedObj &x ) const;
32}
;


 

 1//初始化^Ҏ散列表的例E?/span>
 2explicit HashTable( int size = 101 ) : array(nextPrime( size ) )
 3{ makeEmpty(); }
 4
 5void makeEmpty()
 6{
 7    currentSize = 0;
 8    forint i = 0; i<array.size(); i++ )
 9        array[i].info = EMPTY;
10}



 

 1//使用qx探测q行散列的contains例程
 2bool contains( const HashedObj &x ) const
 3{
 4    return isActive( findPos(x) ); }

 5
 6int findPos( const HashedObj &x ) const
 7{
 8    int offset = 1;
 9    int currentPos = myhash(x);
10    
11    //下面是一个小的trick
12    while ( array[ currentPos ].info != EMPTY && array[ currentPos ].element != x )
13    {
14        currentPos += offset;
15        offset += 2;
16        if( currentPos >= array.size() )
17        currentPos -= array.size();
18    }

19    
20    return currentPos;
21}

22
23bool isActive( int currentPos ) const
24{
25    return array[ currentPos ].info == ACTIVE; }



 

 1//使用qx探测的散列表的insert和remove例程
 2bool insert ( const HashedObj &x )
 3{
 4    int currentPos = findPos( x );
 5    if ( isActive ( currentPos ) )
 6        return false;
 7    
 8    array[ currentPos ] = hashEntry( x, ACTIVE );
 9    if++currentSize > array.size() / 2 )
10        rehash();
11    
12    return true;
13}

14
15bool remove( const HashedObj &x )
16{
17    int currentPos = findPos(x);
18    if ( !isActive( currentPos ) )
19        return false;
20    
21    array[ currentPos ].info = DELETED;//传说中的懒惰删除
22    return true;
23}


  (3)最后一个冲H解x法是双散?double hashing)。对于双散列Q一U流行的选择是f(i)=i*hash2(x)。这个公式是_第二个散列函数应用到xq在距离hash2(x),2hash2(x),
      ...{处探测。hash2(x)选择不好会非常p糕?br>   
.



]]>
数据l构-散列1http://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101935.html罗|?/dc:creator>罗|?/author>Wed, 25 Nov 2009 14:22:00 GMThttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101935.htmlhttp://www.shnenglu.com/xiaoluoluo/comments/101935.htmlhttp://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101935.html#Feedback0http://www.shnenglu.com/xiaoluoluo/comments/commentRss/101935.htmlhttp://www.shnenglu.com/xiaoluoluo/services/trackbacks/101935.html    最q在看Bartosz Milewski的C++ In Action Industrial-Strength Programming TechniquesQ这本书很不错,它不是语a基础教程Q全书主要介l了许多工业强度的编E技术,如清理,隐藏实现l节Q资源管理,׃nQ资源管理,使用标准模板库,重蝲q算W等技术。这是Bartosz Milewski的简?Bartosz MilewskiQC++ In Action 的作者。是Reliable Software公司的总裁QReliable Software公司是一家ؓE序员制造高质量开发工L公司。在q去几年_Bartosz Milewski在多家知名杂志发表了大量技术文章。在微Y工程工作?q期_他担任Windows2000中Content Indexlg的开发主,他曾l在波兰的Wroclaw大学讲授C++~程评Q而且他获得了Wroclaw大学的理论物理学博士学位?/span> q是他ؓq本书管理的blog:http://www.relisoft.com/forums/index.php?s=ee4c0dc7cafef9f08c7c18a6e449b424&showforum=3Q售后服务还不错Q呵呵,以我目前的水q看hq挺累的Q我x好把C++ Primer和effective c++,more effective c++看完再看q本书会比较好,不过着头皮看也有好处,像有时候武侠小说里用非常规Ҏ提高修ؓ有时候也能v到意想不到的效果。言归正传,在这本书中多ơ用到哈希表Q很多地方不明白Q查了书整理一下?br>   
    散列?hash table)的实现常UCؓ散列(hashing),散列是一U用于以常数q_旉执行插入Q删除和查找的技术。但是,那些需要元素间M排序信息的树操作不会得到有效的支持。因此诸如findMin,findMax以及在线性时间内按顺序打印整个表的操作都是散列所不支持的?br>    我们把表的大记作TableSize,我们把每个键映射C0到TableSize-1q个范围中的某个敎ͼq且其攑ֈ适当的单元中。这个映就UCؓ散列函数(hash function),理想情况下它应该q算单ƈ且应该保证Q何两个不同的键映到不同的单元。不q,q是不可能的。因此我们寻找一个散列函敎ͼ该函数要在单元之间均匀分配键。这是散列的基本思想Q剩下的问题则是要选择一个函敎ͼ军_当两个键散列到同一个值的时?UCؓ(collision))应该做什么以及如何确定散列表的大?br>
1.散列函数
    如果输入的键是整敎ͼ一般合理的Ҏ是直接q回"Key mod Tablesize",但Keyh某些不理想的性质Q比如若表的大小?0而键的各位都?。则此时上述标准的散列函数就不是一个好的选择Q好的办法通常是保证表的大是素数Q当输入的键是随机整数时Q散列函C仅运简单而且键的分配也很均匀?br>    通常Q键是字W串Q在q种情Ş下,散列函数需要仔l选择?br>    一U选择Ҏ是把字符串中字符的ASCII码值加hQ下面的例程实现了这U策略?br>   

1int hash( const string &key, int tableSize )
2{
3    int hashVal = 0;
4    forint i=0; i<key.length(); i++ )
5        hashVal += key[i];
6    return hashVal % tableSize;
7}

    上述散列函数实现h单而且能够很快地算出答案。不q如果表很大Q则函数׃会很好地分配键。例如,设TableSize=10007(10007是素?Qƈ设所有的键至?个字W长Q由于ASCII字符的值最多是127Q因此散列函数只能在0-1016之间取|昄q不是一U均匀的分配?br>    另一个散列函数如下表C,q个散列函数假设Key臛_三个字符。?7表示英文字母表的字母个数外加一个空|?29?7×27Q该函数只考察前三个字W,但是如果它们是随机的Q而表的大还?0007Q那么我们就会得C个合理的均衡分布。可是,英文不是随机的。虽?个字W(忽略I格Q有26×26×26=17576U可能的l合Q但查验词汇量够大的联典却揭示出,3个字母的不同l合数实际上只有2851。即使这些组合没有冲H,也不q只有表?8%被真正散列到。因此,虽然很容易计,但是当散列表_大的时候这个函数还是不合适的?br>

1int hash( const string &key, int tableSize )
2{
3    return (key[0]+27*key[1]+729*key[2]) % tableSize
4}


    下面的例E列ZW?U尝试。这个散列函数涉及键中的所有字W,q且一般可以分布得很好Q程序根据Horner法则计算一?7的多式函数。这个散列函数利用了允许溢出q个事实。这可能会引q负敎ͼ因此在末有附加的测试,q个散列函数p的分布而言未必是最好的Q但是确实具有极其简单的优点而且速度也很快。如果键特别长,那么该散列函数计v来将会花费过多的旉。在q种情况下通常做法是不使用所有的字符。此旉的长度和性质媄响选择。例如,键可能是完整的街道地址Q散列函数可以包括街道地址的几个字W,或许也包括城市名和邮政编码的几个字符。有些程序设计h员通过只用奇C|上的字W来实现他们的散列函敎ͼq里有这么一层想法:用计散列函数节省下的时间来补偿由此产生的对均匀分布的函数的dq扰?br>

 1int hash( const string &key, int tableSize )
 2{
 3    int hashVal = 0;
 4    for(int i=0;i<key.length();i++)
 5        hashVal = 37 * hashVal + key[i];
 6    hashVal %= tableSize;
 7    if( hashVal <0 )
 8        hashVal += tableSize;
 9    return hashVal;
10}

    剩下的主要编E细节是解决冲突。如果当一个元素在插入时与一个已l插入的元素散列到相同的|那么׃生一个冲H,q个冲突需要消除?br>


2.分离链接?br>    解决冲突的第一U方法通常UCؓ分离链接?separate chaining),其做法是散列到同一个值的所有元素保留到一个链表中Q可以用标准库中表的实现方法。如果空间很紧,则更可取的方法是避免使用它们(因ؓq些表是双向链表Q浪费空?,为执行search,我们使用散列函数来确定究竟该遍历那个链表Q然后查扄应的表。ؓ执行insertQ我们检查相应的表来定是否该元素已l在表中?如果要插入重复元Q那么通常要留Z个额外的数据成员Q当出现匚w事g时这个数据成员增1),如果q个元素是个新的元素Q那么它被插入到表的前端,q不仅因为方便,而且q因为最后插入的元素最有可能不久再ơ被讉KQ实现分链接法所需要的cL构在下面的例E中l出。散列表l构存储一个链表数l,q个数组在构造函C指定?br>

 1//分离链接散列表的cL?/span>
 2template <typename HashedObj>
 3  class HashTable
 4 {
 5public:
 6    explicit HashTable( int size = 101 );
 7
 8    bool contains( const HashedObj &x ) const;
 9
10   void makeEmpty();
11   void insert( const HashedObj x);
12   void remove( const HashedObj x);
13
14 private:
15    vector<list<HashedObj> > theLists;// >>是c++的一个运符Q而且?gt;长,因此两个>之间需要一个空?br>16    int currentSize;
17    
18    void rehash()
19    int myhash( const HashedObj &x ) const;
20};
21
22int hash( const string &key );
23int hash( int key );
24
25    

    q里不用那些将对象和类的大作为参数的散列函数Q而是使用那些仅以对象为参数的散列函数Qƈ且返回int。散列表cL一个私有的成员函数myhash,q个函数结果分配到一个合适的数组索引中?/p>

 1int myhash( const HashedObj &x ) const
 2{
 3    int hashVal = hash(x);
 4    hashVal %=theLists.size();
 5    if( hashVal < 0)
 6        hashVal += theLists.size();
 7    return hashVal;
 8}

 9     
10

     下面的例E中列出了一个可以存储在一般散列表中的Employeec,该类使用name成员作ؓ键,Employeec通过提供相等性操作符和一个散列函数来实现HashedObj的需求?br>

 1class Employee
 2{
 3public:
 4    const string & getname() const
 5        return name; }
 6    bool operator==const Employee &rhs )  const
 7        return getName() == rhs.getName(); }
 8    bool operator!=const Employee & rhs }
 const
 9        return !(*this == rhs); }
10
11private:
12    string name;
13    double salary;
14    int seniority;
15};
16
17int hash( const Employ &item )
18{
19    return hash( item.getName() );
20}

    实现makeEmpty,contains和remove的程序代码如?br>

 1void makeEmpty()
 2 {
 3    forint i=0; i<theLists.size();i++ )
 4        theLists[i].clear();
 5}

 6
 7bool contains( const HashedObj &x ) const
 8{
 9    const list<HashedObj> & whichList = theLists[myhash(x)];
10    return find( whichList.begin(),whichList.end(),x) !=whichList.end();
11}

12
13bool remove( const HashedObj &x )
14{
15    list<HashedObj> &whichList = theLists[myhash(x)];
16    list<HashedObj>::iterator itr = find(whichList.begin(),whichList.end(),x);
17    if( itr == whichList.end() )
18        return false;
19    whichList.erase( itr );
20    --currentSize;
21    return true;
22}

    下一个操作是插入例程。如果要插入的项已经存在Q那么什么都不做Q否则将其放臌的前端。该元素可以攑֜表的M地方Q此处用push_back是最方便的。whichList是一个引用变?br>

 1bool insert ( const HashedObj &x )
 2{
 3    list<HashedObj> & whichList = theLists[ myhash(x) ];
 4    if( find( whichList.begin(),whichList.end(),x )!=whichList.end() )
 5        return false;
 6    whichList.push_back(x);
 7    
 8    if(++currentSize > theLists.size() )
 9        rehash();
10
11    return true;
12}



 



]]>
q本?/title><link>http://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101919.html</link><dc:creator>罗|?/dc:creator><author>罗|?/author><pubDate>Wed, 25 Nov 2009 10:43:00 GMT</pubDate><guid>http://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101919.html</guid><wfw:comment>http://www.shnenglu.com/xiaoluoluo/comments/101919.html</wfw:comment><comments>http://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101919.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/xiaoluoluo/comments/commentRss/101919.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/xiaoluoluo/services/trackbacks/101919.html</trackback:ping><description><![CDATA[<span style="COLOR: #999999; FONT-FAMILY: 楷体_GB2312">摘自阉K的《这本书?/span><br>    <br><span style="FONT-SIZE: 12pt; COLOR: #808080; FONT-FAMILY: 楷体_GB2312">1.  开始变得成熟是在最痛苦的时候才换到?br><br>    惌q求梦想是在最I的时候才军_?br>  <br>    睡过最舒服的觉是在很篏的时候才发现?br>   <br>    得过最珍贵的东西是在失ȝ时候才知道?br><br>2   惛_一个h的时?距离成了一U温?br><br>    d一个h的时?距离成了一U借口<br><br>    x一个h的时?心情成了一U寂?br><br>    惌一个h的时?寂寞成了一Un?br><br>3   q个时代 房子建得再大<br><br>    也装不下那些x的?br><br>    q个时代 房子盖得再小<br><br>    也容得下那些惛_定的?br></span> <img src ="http://www.shnenglu.com/xiaoluoluo/aggbug/101919.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/xiaoluoluo/" target="_blank">罗|?/a> 2009-11-25 18:43 <a href="http://www.shnenglu.com/xiaoluoluo/archive/2009/11/25/101919.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.haolinhaoju.cn" target="_blank">޾Ʒ˾þþ</a>| <a href="http://www.hanfeng-foods.com.cn" target="_blank">66þôýվȸ</a>| <a href="http://www.269sihu.cn" target="_blank">һƷþð͹</a>| <a href="http://www.gn-online.com.cn" target="_blank">þ˿ྫƷĻ</a>| <a href="http://www.yueyuju.cn" target="_blank">aѹۿþav</a>| <a href="http://www.yahooproxy.cn" target="_blank">þùƷ-þþƷ</a>| <a href="http://www.lskcop.cn" target="_blank">Ʒþþþþþ˿</a>| <a href="http://www.nyeas.cn" target="_blank">99999þþþþ</a>| <a href="http://www.yghzby.cn" target="_blank">ҹƷþþþþӰ777 </a>| <a href="http://www.zusang.cn" target="_blank">ձƷþþþþþþ</a>| <a href="http://www.ttzhan.cn" target="_blank">vaþþþͬ </a>| <a href="http://www.vxbw.cn" target="_blank">þɫ</a>| <a href="http://www.saxie.cn" target="_blank">ھƷþþӰԺ</a>| <a href="http://www.uqbg.cn" target="_blank">һaƬþëƬ</a>| <a href="http://www.vip910.cn" target="_blank">޾ƷþרӰҵ</a>| <a href="http://www.mengdie.net.cn" target="_blank">AVۺϾþ</a>| <a href="http://www.jjygw.cn" target="_blank">avþþþþòվ</a>| <a href="http://www.xqt007.cn" target="_blank">һaɫƬþٸһHƬѷ </a>| <a href="http://www.yinliduo.cn" target="_blank">þ99Ƶ</a>| <a href="http://www.yikafei.cn" target="_blank">һɫþۺ޾Ʒ</a>| <a href="http://www.one-8.cn" target="_blank">þþþ18</a>| <a href="http://www.gqfsm.cn" target="_blank">þþĻ</a>| <a href="http://www.pi04.cn" target="_blank">þ99þëƬһ</a>| <a href="http://www.drxt.com.cn" target="_blank">þþƷ˘AV</a>| <a href="http://www.0470gq.cn" target="_blank">þþþþƵ</a>| <a href="http://www.h3cedu.cn" target="_blank">ɫþþþSWAGƷ</a>| <a href="http://www.chiti.com.cn" target="_blank">þþƷѲ</a>| <a href="http://www.longfee.cn" target="_blank">þۺ˿ձ</a>| <a href="http://www.yuyoo.com.cn" target="_blank">ݺ88ۺϾþþþۺ</a>| <a href="http://www.21tjsports.cn" target="_blank">˾þþAV츾ɫ</a>| <a href="http://www.ryftw.cn" target="_blank">ۺϾþùһ鶹</a>| <a href="http://www.yyfeixiang.cn" target="_blank">޹һɾþþƷۺ</a>| <a href="http://www.transeurope.com.cn" target="_blank">þþƷ</a>| <a href="http://www.ebianlian.cn" target="_blank">þ91Ʒþ91ۺ</a>| <a href="http://www.abcdds.cn" target="_blank">þ99Ʒþþþþþþþ</a>| <a href="http://www.yunea.cn" target="_blank">ݺݾþ</a>| <a href="http://www.nzlx.cn" target="_blank">ۺպþóAV</a>| <a href="http://www.vqcj.cn" target="_blank">޾ƷŮþþ</a>| <a href="http://www.7lcd2h2.cn" target="_blank">ݺɫݺɫۺϾþ</a>| <a href="http://www.ggjkb.cn" target="_blank">ŷþþXXX</a>| <a href="http://www.xiangzen.cn" target="_blank">þþþþ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>