implementation

When should I use type abstraction in embedded systems

I've worked on a number of different embedded systems. They have all used typedefs (or #defines) for types such as UINT32. This is a good technique as it drives home the size of the type to the programmer and makes you more conscious of chances for overflow etc. But on some systems you know that the compiler and processor won't change...

How would you implement a hashtable in language x?

The point of this question is to collect a list of examples of hashtable implementations using arrays in different languages. It would also be nice if someone could throw in a pretty detailed overview of how they work, and what is happening with each example. Edit: Why not just use the built in hash functions in your specific languag...

How would you implement the IEnumerator interface?

I have a class that map objects to objects, but unlike dictionary it maps them both ways. I am now trying to implement a custom IEnumerator interface that iterates through the values. public class Mapper<K,T> : IEnumerable<T>, IEnumerator<T> { C5.TreeDictionary<K,T> KToTMap = new TreeDictionary<K,T>(); C5.HashDictionary<T,K> TT...

How to solve call ambiguity between Generic.IList<T>.this[] and IList.this[]?

I've got a collection that implements an interface that extends both IList<T> and List. public Interface IMySpecialCollection : IList<MyObject>, IList { ... } That means I have two versions of the indexer. I wish the generic implementation to be used, so I implement that one normally: public MyObject this[int index] { .... } I ...

Which should I implement first, PayPal or Google Checkout, on my eCommerce website?

Paypal and Google Checkout will take some time to implement so I'm wanting to know if anyone in the community has installed them and has a recommendation on which to do first. We use the .Net environment. Verdict - Start with Google Checkout. Great customer support, Great multi-language libraries, Simple, fast web interfa...

Implements several interfaces with conflict in signatures

Lasty, I tried to implements an hybrid structure in Java, something that looks like: public class MapOfSet<K, V extends HasKey<K>> implements Set<V>, Map<K, Set<V>> Where HasKey is the following interface: public interface HasKey<K> { public K getKey(); } Unfortunately, there are some conflicts between methos signature of the S...

Singleton: How should it be used

Edit: From another question I provided an answer that has links to a lot of questions/answers about singeltons: More info about singletons here: So I have read the thread Singletons: good design or a crutch? And the argument still rages. I see Singletons as a Design Pattern (good and bad). The problem with Singleton is not the Patte...

How would one code test and set behavior without a special hardware instruction?

Most of the implementations I find require a hardware instruction to do this. However I strongly doubt this is required (if it is, I can't figure out why...) ...

What's a good Common Lisp implementation for Windows?

What's your favourite? See also this related question. ...

Recursive overloading semantics in the Scala REPL - JVM languages

Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String): Unit = {println(foo(2))} gives error: type mismatch; found: Int(2) required: String It seems that you can't define overloaded recursive methods in the REPL. I thought this was a bug in the Scala REPL and filed it, but it was almost instantly closed with...

Can Dns.GetHostEntry ever return an IPHostEntry with an empty AddressList?

Hi, I'm just wondering if there can be a case where the hostname can be successfully resolved but the returned hostEntry.AddressList is empty. Currently I'm doing something like this: IPHostEntry hostEntry = Dns.GetHostEntry("some.hostname.tld"); if (hostEntry.AddressList.Count() < 1) { // can that ever happen? throw new ArgumentEx...

How would I implement a Python bit map?

I wish to implement a 2d bit map class in Python. The class would have the following requirements: Allow the creating of arbitrarily sized 2d bitmaps. i.e. to create an 8 x 8 bitmap (8 bytes), something like: bitmap = Bitmap(8,8) provide an API to access the bits in this 2d map as boolean or even integer values, i.e.: if bitmap[1, 2...

implementing a compiler in "itself"

Hi, Intuitively, it would seems that a compiler for language Foo, cannot itself be written in Foo. More specifically, the first compiler for language Foo cannot be written in Foo, but any subsequent compiler could be written for Foo. But is this actually true? I have some very vague recollection of reading about a language whose first ...

Is there any good JavaScript hash(code/table) implementation out there?

Yes, I know you could use regular objects as associative arrays in JavaScript, but I'd like to use something closer to java's Map's implementation (HashMap, LinkedHashMap etc). Something that could have any kind of data used as key. Are there any good hash(code/table) in JavaScript implementation out there? ...

How does Base 64 handle binary data with zeroes at the end

As I understand the spec, a Base64 encoder a) takes the source binary, and pads it out with zeroes to be a multiple of 24 bytes long. b) it then transcodes it, six bits at a time, to the target set of 64 characters (A..Z, a..z, 0..9, +, -). If it finds the last two bytes (16 bits) have been zero-padded, the last two characters are tra...

uses for state machines

In what areas of programming would I use state machines ? Why ? How could I implement one ? EDIT: please provide a practical example , if it's not too much to ask . ...

C#: How can Dictionary<K,V> implement ICollection<KeyValuePair<K,V>> without having Add(KeyValuePair<K,V>)?

Looking at System.Collections.Generic.Dictionary<TKey, TValue>, it clearly implements ICollection<KeyValuePair<TKey, TValue>>, but doesn't have the required "void Add(KeyValuePair<TKey, TValue> item)" function. This can also be seen when trying to initialize a Dictionary like this: private const Dictionary<string, int> PropertyIDs = ne...

Why to Use Explicit Interface Implementation To Invoke a Protected Method?

When browsing ASP.NET MVC source code in codeplex, I found it is common to have a class explicitly implementing interface. The explicitly implemented method/property then invoke another "protected virtual" method/property with same name. For example, public class MvcHandler : IHttpHandler, IRequiresSessionState { protected virtua...

NHibernate IInterceptor implementation(add properties to DB table that original domain class doesn't have)

How is possible to set some special column values when update/insert entities via NHibernate without extending domain classes with special properties? for example: in my case i would like to get object and just moment before update/insert db add to that object some additional information (like user id or computer name) by using IInterce...

How is the NodeList implemented?

The DOM NodeList (as returned e.g. by element.getElementsByTagName) is an interesting object, in that it is not a snapshot, but reflects changes to the document made after you have created the NodeList. I was wondering how one would implement such a collection: Completely lazy evaluation must be horribly slow, but keeping a cached vers...