Click here to Skip to main content
Licence 
First Posted 2 Apr 2002
Views 49,966
Bookmarked 12 times

Multi index array

By | 2 Apr 2002 | Article
A class which behaves as a simple array, but additionally supports binary search functionality.

The Problem

Let's say that we have structure "Person" with attributes "Name", "Surname", "Age", etc. All "Persons" are kept in an array, and usually we need to find a person by name or surname or by another attribute.

Those who have read my article Extended collections is familiar with the CSortedArray class and knows its disadvantages:

  • During sorting the array has changed the order of the array. Sometimes is very important that you don't change the order of the array in order to have the possibility for binary searching.

  • It is possible sort only by one trait (individual characteristic)

We can conclude that the sorted array doesn't match our requirements, so I decided to implement a class which behaves as a simple array, but additionally supports binary search functionality.

The Multi Index Array

‘Multi Index Array' class supports:

  • Array functionality, most of you will recognize MFC CArray
  • Lookup - a binary search that returns -1 on failure.
  • Search - a binary search that returns the nearest element on failure.
  • SearchIndexRange - a binary search. If data is not unique then it returns a valid array index range

Why a MFC collection and not STL?

  • Too many different implementations with different extensions.
  • The best libraries are made by yourself :)

Anyway, I hope that it will be useful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Audrius Vasiliauskas

Business Analyst

Lithuania Lithuania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Apr 2002
Article Copyright 2002 by Audrius Vasiliauskas
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid