1 //
2 //  KTMatrixSparseImp
3 //  KTMatrix collection class cluster
4 //
5 //  KTMatrix class cluster implementation subclass
6 //  Fast access to a mass-allocated chunk of memory
7 //  Ideal for sparsely-populated matrices
8 //  Sacrifices some speed for a considerable potential memory saving
9 //  Uses a O(log(n)) binary search algorithm to find object
10 //
11 //  Copyright (c) 2002 Chris Purcell. All rights reserved.
12 //
13 //  You may use this code for whatever purposes you wish.
14 //  This code comes with no warranties, implied or otherwise.
15 //  Using it may damage your data. It shouldn't, but save a copy first.
16 //  That's a good idea anyway, actually.
17 //
18 
19 #import <Foundation/Foundation.h>
20 #import "KTMatrix.h"
21 
22 @interface KTMatrixSparseImp : KTMatrix
23 {   // The hashing object, used to translate locations to useful numbers
24     id<KTLocationHash> hash;
25     BOOL hashIsCoordinateOptimized;
26 
27     // A count of the objects we are storing
28     unsigned count;
29 
30     // memory stores the elements of the matrix
31     // It is sorted by hash value to enable fast binary searching
32     void *memory;
33 }
34 
35 - (id)initWithMatrixData:(NSDictionary *)matrixData
36             locationHash:(id<KTLocationHash>)locationHash;
37 - (id)initWithLocationHash:(id<KTLocationHash>)locationHash
38                     object:(id)object
39           atHashedLocation:(unsigned)loc;
40 
41 @end
42