@@ -6,30 +6,31 @@ var ME = EVEoj.SDD.Table,
66 E = EVEoj ,
77 SDD = EVEoj . data ,
88
9- // default object properties
10- _D = {
11- 'src' : null , // the EVEoj.data source that created this table
12- 'name' : null , // the name of this table
13- 'keyname' : null , // the primary key name
14- 'columns' : [ ] , // the list of columns
15- 'colmap' : { } , // a reverse lookup map for column indexes
16- 'subkeys' : [ ] , // any subkeys (this implies a nested entry structure)
17- 'indexes' : [ ] , // indexes available for secondary entry lookups
18- 'segments' : [ ] // the data for this table, in segments
19- } ,
20-
219 _P = { } , // private methods
2210 P = { } // public methods
2311 ;
2412
13+ // default object properties
14+ ME . D = {
15+ 'src' : null , // the EVEoj.SDD.Source that owns this table
16+ 'name' : null , // the name of this table
17+ 'keyname' : null , // the primary key name
18+ 'columns' : [ ] , // the list of columns
19+ 'colmap' : { } , // a reverse lookup map for column indexes
20+ 'subkeys' : [ ] , // any subkeys (this implies a nested entry structure)
21+ 'data' : { } , // the data for this table (shallow references into raw data from source)
22+ 'segments' : [ ] , // the segment information for this table
23+ 'length' : 0 , // the total number of entries in this table
24+ 'loaded' : 0 // the total number of currently loaded entries
25+ } ;
2526ME . Create = function ( name , src , meta ) {
2627 var obj ,
2728 i ,
2829 keyarr
2930 ;
3031
3132 obj = E . create ( P ) ;
32- E . extend ( true , obj , _D ) ;
33+ E . extend ( true , obj , ME . D ) ;
3334
3435 // sort out relevant metadata details
3536 obj . src = src ;
@@ -38,12 +39,12 @@ ME.Create = function (name, src, meta) {
3839 // determine the source(s) of this table's data
3940 if ( meta . hasOwnProperty ( 'j' ) ) {
4041 // only one segment and it is stored with other stuff
41- obj . segments . push ( { 'min' : 0 , 'max' : - 1 , 'tag' : meta [ 'j' ] , 'data ' : false , 'p' : null } ) ;
42+ obj . segments . push ( { 'min' : 0 , 'max' : - 1 , 'tag' : meta [ 'j' ] , 'loaded ' : false , 'p' : null } ) ;
4243 }
4344 else if ( meta . hasOwnProperty ( 's' ) ) {
4445 // at least one segment that is stored independently
4546 for ( i = 0 ; i < meta [ 's' ] . length ; i ++ ) {
46- obj . segments . push ( { 'min' : meta [ 's' ] [ i ] [ 1 ] , 'max' : meta [ 's' ] [ i ] [ 2 ] , 'tag' : name + '_' + meta [ 's' ] [ i ] [ 0 ] , 'data ' : false , 'p' : null } ) ;
47+ obj . segments . push ( { 'min' : meta [ 's' ] [ i ] [ 1 ] , 'max' : meta [ 's' ] [ i ] [ 2 ] , 'tag' : name + '_' + meta [ 's' ] [ i ] [ 0 ] , 'loaded ' : false , 'p' : null } ) ;
4748 }
4849 }
4950
@@ -59,9 +60,10 @@ ME.Create = function (name, src, meta) {
5960 obj . keyname = keyarr . shift ( ) ;
6061 obj . subkeys . push ( keyarr ) ;
6162 }
62-
63- if ( meta . hasOwnProperty ( 'i' ) ) {
64- obj . indexes = obj . meta [ 'i' ] ;
63+
64+ // grab the length
65+ if ( meta . hasOwnProperty ( 'l' ) ) {
66+ obj . length = meta [ 'l' ] ;
6567 }
6668
6769 return obj ;
@@ -77,16 +79,19 @@ P.GetEntry = function (key) {
7779 // is for segment comparison, string is for object property lookup
7880 nkey = parseInt ( key ) ;
7981 if ( isNaN ( nkey ) ) return null ;
80- skey = nkey . toString ( 10 ) ;
82+ skey = nkey . toString ( 10 ) ;
83+ if ( this . data . hasOwnProperty ( skey ) ) return this . data [ skey ] ;
84+
85+ // if we don't have this key, determine if we ought to by now
8186 for ( i = 0 ; i < this . segments . length ; i ++ ) {
8287 if ( nkey >= this . segments [ i ] . min && ( nkey <= this . segments [ i ] . max || this . segments [ i ] . max == - 1 ) ) {
8388 // the key should be in this segment
84- if ( this . segments [ i ] . data ) {
89+ if ( this . segments [ i ] . loaded ) return null ; // {
8590 // the segment is loaded, so either we have this key or it doesn't exist
86- if ( this . segments [ i ] . data . hasOwnProperty ( skey ) ) return this . segments [ i ] . data [ skey ] ;
87- else return null ;
88- }
89- else return false ; // the segment isn't not loaded yet
91+ // if (this.segments[i].data.hasOwnProperty(skey)) return this.segments[i].data[skey];
92+ // else return null;
93+ // }
94+ else return false ; // the segment isn't loaded yet
9095 }
9196 }
9297
@@ -111,9 +116,17 @@ _P.SegLoadDone = function(tag, data, done, p, ctx) {
111116 done . has ++ ;
112117 for ( i = 0 ; i < this . segments . length ; i ++ ) {
113118 if ( this . segments [ i ] . tag != tag ) continue ;
114- this . segments [ i ] . data = data ;
119+ if ( data [ 'tables' ] . hasOwnProperty ( this . name ) && data [ 'tables' ] [ this . name ] . hasOwnProperty ( 'd' ) ) {
120+ E . extend ( this . data , data [ 'tables' ] [ this . name ] [ 'd' ] ) ;
121+ if ( data [ 'tables' ] [ this . name ] . hasOwnProperty ( 'L' ) ) {
122+ this . loaded += data [ 'tables' ] [ this . name ] [ 'L' ] ;
123+ }
124+ else if ( done . needs == 1 ) {
125+ this . loaded = this . length ;
126+ }
127+ }
115128 break ;
116- }
129+ }
117130 if ( done . has >= done . needs ) p . resolveWith ( ctx , [ this ] ) ;
118131 else p . notifyWith ( ctx , [ this , done . has , done . needs ] ) ;
119132} ;
@@ -140,7 +153,7 @@ P.Load = function(opts) {
140153 // load all segments
141154 all_needs = [ ] ;
142155 for ( i = 0 ; i < this . segments . length ; i ++ ) {
143- if ( ! this . segments [ i ] . data ) {
156+ if ( ! this . segments [ i ] . loaded ) {
144157 // this segment not yet loaded
145158 all_needs . push ( i ) ;
146159 }
@@ -181,9 +194,9 @@ P.Load = function(opts) {
181194 }
182195
183196 if ( segment === - 1 ) return p . rejectWith ( o . ctx , [ this , 'badkey' , 'invalid key; no segment contains it' ] ) . promise ( ) ;
184- if ( segment . data ) return p . resolveWith ( o . ctx , [ this ] ) . promise ( ) ;
197+ if ( segment . loaded ) return p . resolveWith ( o . ctx , [ this ] ) . promise ( ) ;
185198
186- if ( segment . p == null ) segment . p = this . src . LoadFile ( segment . tag ) ;
199+ if ( segment . p == null ) segment . p = this . src . LoadTag ( segment . tag ) ;
187200 done = { 'needs' : 1 , 'has' : 0 } ;
188201 segment . p
189202 . done ( function ( tag , data ) { _P . SegLoadDone . apply ( self , [ tag , data , done , p , o . ctx ] ) } )
@@ -192,46 +205,14 @@ P.Load = function(opts) {
192205 return p . promise ( ) ;
193206 }
194207} ;
195-
196- } ) ( ) ;
197-
198- /*
199- EVEoj.data.EntryIter = EVEoj.data.EntryIter || {};
200- (function ($) {
201- var ME = EVEoj.data.EntryIter,
202- E = EVEoj,
203- D = EVEoj.data,
204- _D = {
205- 'curidx': 0,
206- 'curseg': 0,
207- 'tbl': null
208- },
209- _P = {}
210- ;
211-
212- ME.Create = function (tbl) {
213- var obj
214- ;
215208
216- obj = Object.create(_P),
217- $.extend(true, obj, _D);
218- obj.tbl = tbl;
209+ P . ColIter = function ( colname ) {
210+ var colnum ;
211+ if ( this . colmap . hasOwnProperty ( colname ) ) {
212+ colnum = this . colmap [ colname ] ;
213+ return function ( e ) { return e [ colnum ] } ;
214+ }
215+ else return function ( e ) { return undefined } ;
216+ } ;
219217
220- return obj;
221- };
222-
223- _P.HasNext = function () {
224- if (this.curidx < this.keyset.length) return true;
225- };
226-
227- _P.Next = function () {
228- var sys;
229-
230- sys = S.Create();
231- if (!sys.LoadID(this.src, this.tbl, this.keyset[this.curidx])) sys = null;
232- this.curidx++;
233- return sys;
234- };
235-
236- })(jQuery);
237- */
218+ } ) ( ) ;
0 commit comments