Hash table in Swift?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
phhnguyen
Posts: 1541
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Hash table in Swift?

Post by phhnguyen »

I have started writing a new chess engine in Swift and now working with the hash table.

In Swift I may simply use an array for the hash table. However IMO that has some drawbacks:

- have to allocate all array items (hash table cells) one by one. It may take time for a huge array
- waste too much memory since for each small items the OS may take some extra memory for managing it
- memory fragment may be so serious

Any solution / idea to deal with hash table in Swift?
tttony
Posts: 278
Joined: Sun Apr 24, 2011 12:33 am

Re: Hash table in Swift?

Post by tttony »

I've never touched Swift but I was curious in why you can't do it

A quick search gave this: http://stackoverflow.com/questions/2699 ... use-malloc

An it seems that there is no a native way to do it, only bridging like it says in the answer
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Hash table in Swift?

Post by kbhearn »

User avatar
phhnguyen
Posts: 1541
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Hash table in Swift?

Post by phhnguyen »

For developing on IDE XCode we can mix code between C, C++, Objective-C and Swift. The links you show me actually suggest to use C++ code for allocating memory.

Yes we can but it is not Swift way.

(Similar, I can re-use all my C++ code in XCode but it is not my purpose of developing an engine in Swift)
User avatar
phhnguyen
Posts: 1541
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Hash table in Swift?

Post by phhnguyen »

Look like UnsafeMutablePointer has some potentials. Reading and trying :)