Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 1 | (*
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one
|
| 3 | * or more contributor license agreements. See the NOTICE file
|
| 4 | * distributed with this work for additional information
|
| 5 | * regarding copyright ownership. The ASF licenses this file
|
| 6 | * to you under the Apache License, Version 2.0 (the
|
| 7 | * "License"); you may not use this file except in compliance
|
| 8 | * with the License. You may obtain a copy of the License at
|
| 9 | *
|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 11 | *
|
| 12 | * Unless required by applicable law or agreed to in writing,
|
| 13 | * software distributed under the License is distributed on an
|
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 | * KIND, either express or implied. See the License for the
|
| 16 | * specific language governing permissions and limitations
|
| 17 | * under the License.
|
| 18 | *)
|
| 19 |
|
| 20 | unit Thrift.Collections;
|
| 21 |
|
| 22 | interface
|
| 23 |
|
| 24 | uses
|
| 25 | Generics.Collections, Generics.Defaults, Thrift.Utils;
|
| 26 |
|
| 27 | type
|
| 28 |
|
| 29 | {$IF CompilerVersion < 21.0}
|
| 30 | TArray<T> = array of T;
|
| 31 | {$IFEND}
|
| 32 |
|
| 33 | IThriftContainer = interface
|
| 34 | ['{93DEF5A0-D162-461A-AB22-5B4EE0734050}']
|
| 35 | function ToString: string;
|
| 36 | end;
|
| 37 |
|
| 38 | IThriftDictionary<TKey,TValue> = interface(IThriftContainer)
|
| 39 | ['{25EDD506-F9D1-4008-A40F-5940364B7E46}']
|
| 40 | function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
|
| 41 |
|
| 42 | function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
|
| 43 | function GetValues: TDictionary<TKey,TValue>.TValueCollection;
|
| 44 | function GetItem(const Key: TKey): TValue;
|
| 45 | procedure SetItem(const Key: TKey; const Value: TValue);
|
| 46 | function GetCount: Integer;
|
| 47 |
|
| 48 | procedure Add(const Key: TKey; const Value: TValue);
|
| 49 | procedure Remove(const Key: TKey);
|
| 50 | {$IF CompilerVersion >= 21.0}
|
| 51 | function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
|
| 52 | {$IFEND}
|
| 53 | procedure Clear;
|
| 54 | procedure TrimExcess;
|
| 55 | function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
|
| 56 | procedure AddOrSetValue(const Key: TKey; const Value: TValue);
|
| 57 | function ContainsKey(const Key: TKey): Boolean;
|
| 58 | function ContainsValue(const Value: TValue): Boolean;
|
| 59 | function ToArray: TArray<TPair<TKey,TValue>>;
|
| 60 |
|
| 61 | property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
|
| 62 | property Count: Integer read GetCount;
|
| 63 | property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
|
| 64 | property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
|
| 65 | end;
|
| 66 |
|
| 67 | TThriftDictionaryImpl<TKey,TValue> = class( TInterfacedObject, IThriftDictionary<TKey,TValue>)
|
| 68 | private
|
| 69 | FDictionaly : TDictionary<TKey,TValue>;
|
| 70 | protected
|
| 71 | function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
|
| 72 |
|
| 73 | function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
|
| 74 | function GetValues: TDictionary<TKey,TValue>.TValueCollection;
|
| 75 | function GetItem(const Key: TKey): TValue;
|
| 76 | procedure SetItem(const Key: TKey; const Value: TValue);
|
| 77 | function GetCount: Integer;
|
| 78 |
|
| 79 | procedure Add(const Key: TKey; const Value: TValue);
|
| 80 | procedure Remove(const Key: TKey);
|
| 81 | {$IF CompilerVersion >= 21.0}
|
| 82 | function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
|
| 83 | {$IFEND}
|
| 84 | procedure Clear;
|
| 85 | procedure TrimExcess;
|
| 86 | function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
|
| 87 | procedure AddOrSetValue(const Key: TKey; const Value: TValue);
|
| 88 | function ContainsKey(const Key: TKey): Boolean;
|
| 89 | function ContainsValue(const Value: TValue): Boolean;
|
| 90 | function ToArray: TArray<TPair<TKey,TValue>>;
|
| 91 | property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
|
| 92 | property Count: Integer read GetCount;
|
| 93 | property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
|
| 94 | property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
|
| 95 | public
|
| 96 | constructor Create(ACapacity: Integer = 0);
|
| 97 | destructor Destroy; override;
|
| 98 | end;
|
| 99 |
|
| 100 | IThriftList<T> = interface(IThriftContainer)
|
| 101 | ['{29BEEE31-9CB4-401B-AA04-5148A75F473B}']
|
| 102 | function GetEnumerator: TEnumerator<T>;
|
| 103 | function GetCapacity: Integer;
|
| 104 | procedure SetCapacity(Value: Integer);
|
| 105 | function GetCount: Integer;
|
| 106 | procedure SetCount(Value: Integer);
|
| 107 | function GetItem(Index: Integer): T;
|
| 108 | procedure SetItem(Index: Integer; const Value: T);
|
| 109 | function Add(const Value: T): Integer;
|
| 110 | procedure AddRange(const Values: array of T); overload;
|
| 111 | procedure AddRange(const Collection: IEnumerable<T>); overload;
|
| 112 | procedure AddRange(Collection: TEnumerable<T>); overload;
|
| 113 | procedure Insert(Index: Integer; const Value: T);
|
| 114 | procedure InsertRange(Index: Integer; const Values: array of T); overload;
|
| 115 | procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
|
| 116 | procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
|
| 117 | function Remove(const Value: T): Integer;
|
| 118 | procedure Delete(Index: Integer);
|
| 119 | procedure DeleteRange(AIndex, ACount: Integer);
|
| 120 | function Extract(const Value: T): T;
|
| 121 | {$IF CompilerVersion >= 21.0}
|
| 122 | procedure Exchange(Index1, Index2: Integer);
|
| 123 | procedure Move(CurIndex, NewIndex: Integer);
|
| 124 | function First: T;
|
| 125 | function Last: T;
|
| 126 | {$IFEND}
|
| 127 | procedure Clear;
|
| 128 | function Contains(const Value: T): Boolean;
|
| 129 | function IndexOf(const Value: T): Integer;
|
| 130 | function LastIndexOf(const Value: T): Integer;
|
| 131 | procedure Reverse;
|
| 132 | procedure Sort; overload;
|
| 133 | procedure Sort(const AComparer: IComparer<T>); overload;
|
| 134 | function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
|
| 135 | function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
|
| 136 | procedure TrimExcess;
|
| 137 | function ToArray: TArray<T>;
|
| 138 | property Capacity: Integer read GetCapacity write SetCapacity;
|
| 139 | property Count: Integer read GetCount write SetCount;
|
| 140 | property Items[Index: Integer]: T read GetItem write SetItem; default;
|
| 141 | end;
|
| 142 |
|
| 143 | TThriftListImpl<T> = class( TInterfacedObject, IThriftList<T>)
|
| 144 | private
|
| 145 | FList : TList<T>;
|
| 146 | protected
|
| 147 | function GetEnumerator: TEnumerator<T>;
|
| 148 | function GetCapacity: Integer;
|
| 149 | procedure SetCapacity(Value: Integer);
|
| 150 | function GetCount: Integer;
|
| 151 | procedure SetCount(Value: Integer);
|
| 152 | function GetItem(Index: Integer): T;
|
| 153 | procedure SetItem(Index: Integer; const Value: T);
|
| 154 | function Add(const Value: T): Integer;
|
| 155 | procedure AddRange(const Values: array of T); overload;
|
| 156 | procedure AddRange(const Collection: IEnumerable<T>); overload;
|
| 157 | procedure AddRange(Collection: TEnumerable<T>); overload;
|
| 158 | procedure Insert(Index: Integer; const Value: T);
|
| 159 | procedure InsertRange(Index: Integer; const Values: array of T); overload;
|
| 160 | procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
|
| 161 | procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
|
| 162 | function Remove(const Value: T): Integer;
|
| 163 | procedure Delete(Index: Integer);
|
| 164 | procedure DeleteRange(AIndex, ACount: Integer);
|
| 165 | function Extract(const Value: T): T;
|
| 166 | {$IF CompilerVersion >= 21.0}
|
| 167 | procedure Exchange(Index1, Index2: Integer);
|
| 168 | procedure Move(CurIndex, NewIndex: Integer);
|
| 169 | function First: T;
|
| 170 | function Last: T;
|
| 171 | {$IFEND}
|
| 172 | procedure Clear;
|
| 173 | function Contains(const Value: T): Boolean;
|
| 174 | function IndexOf(const Value: T): Integer;
|
| 175 | function LastIndexOf(const Value: T): Integer;
|
| 176 | procedure Reverse;
|
| 177 | procedure Sort; overload;
|
| 178 | procedure Sort(const AComparer: IComparer<T>); overload;
|
| 179 | function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
|
| 180 | function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
|
| 181 | procedure TrimExcess;
|
| 182 | function ToArray: TArray<T>;
|
| 183 | property Capacity: Integer read GetCapacity write SetCapacity;
|
| 184 | property Count: Integer read GetCount write SetCount;
|
| 185 | property Items[Index: Integer]: T read GetItem write SetItem; default;
|
| 186 | public
|
| 187 | constructor Create;
|
| 188 | destructor Destroy; override;
|
| 189 | end;
|
| 190 |
|
| 191 | IHashSet<TValue> = interface(IThriftContainer)
|
| 192 | ['{0923A3B5-D4D4-48A8-91AD-40238E2EAD66}']
|
| 193 | function GetEnumerator: TEnumerator<TValue>;
|
| 194 | function GetIsReadOnly: Boolean;
|
| 195 | function GetCount: Integer;
|
| 196 | property Count: Integer read GetCount;
|
| 197 | property IsReadOnly: Boolean read GetIsReadOnly;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 198 | procedure Add( const item: TValue);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 199 | procedure Clear;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 200 | function Contains( const item: TValue): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 201 | procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 202 | function Remove( const item: TValue ): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 203 | end;
|
| 204 |
|
| 205 | THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>)
|
| 206 | private
|
| 207 | FDictionary : IThriftDictionary<TValue,Integer>;
|
| 208 | FIsReadOnly: Boolean;
|
| 209 | protected
|
| 210 | function GetEnumerator: TEnumerator<TValue>;
|
| 211 | function GetIsReadOnly: Boolean;
|
| 212 | function GetCount: Integer;
|
| 213 | property Count: Integer read GetCount;
|
| 214 | property IsReadOnly: Boolean read FIsReadOnly;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 215 | procedure Add( const item: TValue);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 216 | procedure Clear;
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 217 | function Contains( const item: TValue): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 218 | procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 219 | function Remove( const item: TValue ): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 220 | public
|
| 221 | constructor Create;
|
| 222 | end;
|
| 223 |
|
| 224 | implementation
|
| 225 |
|
| 226 | { THashSetImpl<TValue> }
|
| 227 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 228 | procedure THashSetImpl<TValue>.Add( const item: TValue);
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 229 | begin
|
| 230 | if not FDictionary.ContainsKey(item) then
|
| 231 | begin
|
| 232 | FDictionary.Add( item, 0);
|
| 233 | end;
|
| 234 | end;
|
| 235 |
|
| 236 | procedure THashSetImpl<TValue>.Clear;
|
| 237 | begin
|
| 238 | FDictionary.Clear;
|
| 239 | end;
|
| 240 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 241 | function THashSetImpl<TValue>.Contains( const item: TValue): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 242 | begin
|
| 243 | Result := FDictionary.ContainsKey(item);
|
| 244 | end;
|
| 245 |
|
| 246 | procedure THashSetImpl<TValue>.CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
|
| 247 | var
|
| 248 | i : Integer;
|
| 249 | Enumlator : TEnumerator<TValue>;
|
| 250 | begin
|
| 251 | Enumlator := GetEnumerator;
|
| 252 | while Enumlator.MoveNext do
|
| 253 | begin
|
| 254 | A[arrayIndex] := Enumlator.Current;
|
| 255 | Inc(arrayIndex);
|
| 256 | end;
|
| 257 | end;
|
| 258 |
|
| 259 | constructor THashSetImpl<TValue>.Create;
|
| 260 | begin
|
| 261 | inherited;
|
| 262 | FDictionary := TThriftDictionaryImpl<TValue,Integer>.Create;
|
| 263 | end;
|
| 264 |
|
| 265 | function THashSetImpl<TValue>.GetCount: Integer;
|
| 266 | begin
|
| 267 | Result := FDictionary.Count;
|
| 268 | end;
|
| 269 |
|
| 270 | function THashSetImpl<TValue>.GetEnumerator: TEnumerator<TValue>;
|
| 271 | begin
|
| 272 | Result := FDictionary.Keys.GetEnumerator;
|
| 273 | end;
|
| 274 |
|
| 275 | function THashSetImpl<TValue>.GetIsReadOnly: Boolean;
|
| 276 | begin
|
| 277 | Result := FIsReadOnly;
|
| 278 | end;
|
| 279 |
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 280 | function THashSetImpl<TValue>.Remove( const item: TValue): Boolean;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 281 | begin
|
| 282 | Result := False;
|
| 283 | if FDictionary.ContainsKey( item ) then
|
| 284 | begin
|
| 285 | FDictionary.Remove( item );
|
| 286 | Result := not FDictionary.ContainsKey( item );
|
| 287 | end;
|
| 288 | end;
|
| 289 |
|
| 290 | { TThriftDictionaryImpl<TKey, TValue> }
|
| 291 |
|
| 292 | procedure TThriftDictionaryImpl<TKey, TValue>.Add(const Key: TKey;
|
| 293 | const Value: TValue);
|
| 294 | begin
|
| 295 | FDictionaly.Add( Key, Value);
|
| 296 | end;
|
| 297 |
|
| 298 | procedure TThriftDictionaryImpl<TKey, TValue>.AddOrSetValue(const Key: TKey;
|
| 299 | const Value: TValue);
|
| 300 | begin
|
| 301 | FDictionaly.AddOrSetValue( Key, Value);
|
| 302 | end;
|
| 303 |
|
| 304 | procedure TThriftDictionaryImpl<TKey, TValue>.Clear;
|
| 305 | begin
|
| 306 | FDictionaly.Clear;
|
| 307 | end;
|
| 308 |
|
| 309 | function TThriftDictionaryImpl<TKey, TValue>.ContainsKey(
|
| 310 | const Key: TKey): Boolean;
|
| 311 | begin
|
| 312 | Result := FDictionaly.ContainsKey( Key );
|
| 313 | end;
|
| 314 |
|
| 315 | function TThriftDictionaryImpl<TKey, TValue>.ContainsValue(
|
| 316 | const Value: TValue): Boolean;
|
| 317 | begin
|
| 318 | Result := FDictionaly.ContainsValue( Value );
|
| 319 | end;
|
| 320 |
|
| 321 | constructor TThriftDictionaryImpl<TKey, TValue>.Create(ACapacity: Integer);
|
| 322 | begin
|
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 323 | inherited Create;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 324 | FDictionaly := TDictionary<TKey,TValue>.Create( ACapacity );
|
| 325 | end;
|
| 326 |
|
| 327 | destructor TThriftDictionaryImpl<TKey, TValue>.Destroy;
|
| 328 | begin
|
| 329 | FDictionaly.Free;
|
| 330 | inherited;
|
| 331 | end;
|
| 332 |
|
| 333 | {$IF CompilerVersion >= 21.0}
|
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 334 | function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 335 | begin
|
| 336 | Result := FDictionaly.ExtractPair( Key);
|
| 337 | end;
|
| 338 | {$IFEND}
|
| 339 |
|
| 340 | function TThriftDictionaryImpl<TKey, TValue>.GetCount: Integer;
|
| 341 | begin
|
| 342 | Result := FDictionaly.Count;
|
| 343 | end;
|
| 344 |
|
| 345 | function TThriftDictionaryImpl<TKey, TValue>.GetEnumerator: TEnumerator<TPair<TKey, TValue>>;
|
| 346 | begin
|
| 347 | Result := FDictionaly.GetEnumerator;
|
| 348 | end;
|
| 349 |
|
| 350 | function TThriftDictionaryImpl<TKey, TValue>.GetItem(const Key: TKey): TValue;
|
| 351 | begin
|
| 352 | Result := FDictionaly.Items[Key];
|
| 353 | end;
|
| 354 |
|
| 355 | function TThriftDictionaryImpl<TKey, TValue>.GetKeys: TDictionary<TKey, TValue>.TKeyCollection;
|
| 356 | begin
|
| 357 | Result := FDictionaly.Keys;
|
| 358 | end;
|
| 359 |
|
| 360 | function TThriftDictionaryImpl<TKey, TValue>.GetValues: TDictionary<TKey, TValue>.TValueCollection;
|
| 361 | begin
|
| 362 | Result := FDictionaly.Values;
|
| 363 | end;
|
| 364 |
|
| 365 | procedure TThriftDictionaryImpl<TKey, TValue>.Remove(const Key: TKey);
|
| 366 | begin
|
| 367 | FDictionaly.Remove( Key );
|
| 368 | end;
|
| 369 |
|
| 370 | procedure TThriftDictionaryImpl<TKey, TValue>.SetItem(const Key: TKey;
|
| 371 | const Value: TValue);
|
| 372 | begin
|
| 373 | FDictionaly.AddOrSetValue( Key, Value);
|
| 374 | end;
|
| 375 |
|
| 376 | function TThriftDictionaryImpl<TKey, TValue>.ToArray: TArray<TPair<TKey, TValue>>;
|
| 377 | {$IF CompilerVersion < 22.0}
|
| 378 | var
|
| 379 | x : TPair<TKey, TValue>;
|
| 380 | i : Integer;
|
| 381 | {$IFEND}
|
| 382 | begin
|
| 383 | {$IF CompilerVersion < 22.0}
|
| 384 | SetLength(Result, Count);
|
| 385 | i := 0;
|
| 386 | for x in FDictionaly do
|
| 387 | begin
|
| 388 | Result[i] := x;
|
| 389 | Inc( i );
|
| 390 | end;
|
| 391 | {$ELSE}
|
| 392 | Result := FDictionaly.ToArray;
|
| 393 | {$IFEND}
|
| 394 | end;
|
| 395 |
|
| 396 | procedure TThriftDictionaryImpl<TKey, TValue>.TrimExcess;
|
| 397 | begin
|
| 398 | FDictionaly.TrimExcess;
|
| 399 | end;
|
| 400 |
|
| 401 | function TThriftDictionaryImpl<TKey, TValue>.TryGetValue(const Key: TKey;
|
| 402 | out Value: TValue): Boolean;
|
| 403 | begin
|
| 404 | Result := FDictionaly.TryGetValue( Key, Value);
|
| 405 | end;
|
| 406 |
|
| 407 | { TThriftListImpl<T> }
|
| 408 |
|
| 409 | function TThriftListImpl<T>.Add(const Value: T): Integer;
|
| 410 | begin
|
| 411 | Result := FList.Add( Value );
|
| 412 | end;
|
| 413 |
|
| 414 | procedure TThriftListImpl<T>.AddRange(Collection: TEnumerable<T>);
|
| 415 | begin
|
| 416 | FList.AddRange( Collection );
|
| 417 | end;
|
| 418 |
|
| 419 | procedure TThriftListImpl<T>.AddRange(const Collection: IEnumerable<T>);
|
| 420 | begin
|
| 421 | FList.AddRange( Collection );
|
| 422 | end;
|
| 423 |
|
| 424 | procedure TThriftListImpl<T>.AddRange(const Values: array of T);
|
| 425 | begin
|
| 426 | FList.AddRange( Values );
|
| 427 | end;
|
| 428 |
|
| 429 | function TThriftListImpl<T>.BinarySearch(const Item: T;
|
| 430 | out Index: Integer): Boolean;
|
| 431 | begin
|
| 432 | Result := FList.BinarySearch( Item, Index);
|
| 433 | end;
|
| 434 |
|
| 435 | function TThriftListImpl<T>.BinarySearch(const Item: T; out Index: Integer;
|
| 436 | const AComparer: IComparer<T>): Boolean;
|
| 437 | begin
|
| 438 | Result := FList.BinarySearch( Item, Index, AComparer);
|
| 439 | end;
|
| 440 |
|
| 441 | procedure TThriftListImpl<T>.Clear;
|
| 442 | begin
|
| 443 | FList.Clear;
|
| 444 | end;
|
| 445 |
|
| 446 | function TThriftListImpl<T>.Contains(const Value: T): Boolean;
|
| 447 | begin
|
| 448 | Result := FList.Contains( Value );
|
| 449 | end;
|
| 450 |
|
| 451 | constructor TThriftListImpl<T>.Create;
|
| 452 | begin
|
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 453 | inherited;
|
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 454 | FList := TList<T>.Create;
|
| 455 | end;
|
| 456 |
|
| 457 | procedure TThriftListImpl<T>.Delete(Index: Integer);
|
| 458 | begin
|
| 459 | FList.Delete( Index )
|
| 460 | end;
|
| 461 |
|
| 462 | procedure TThriftListImpl<T>.DeleteRange(AIndex, ACount: Integer);
|
| 463 | begin
|
| 464 | FList.DeleteRange( AIndex, ACount)
|
| 465 | end;
|
| 466 |
|
| 467 | destructor TThriftListImpl<T>.Destroy;
|
| 468 | begin
|
| 469 | FList.Free;
|
| 470 | inherited;
|
| 471 | end;
|
| 472 |
|
| 473 | {$IF CompilerVersion >= 21.0}
|
| 474 | procedure TThriftListImpl<T>.Exchange(Index1, Index2: Integer);
|
| 475 | begin
|
| 476 | FList.Exchange( Index1, Index2 )
|
| 477 | end;
|
| 478 | {$IFEND}
|
| 479 |
|
| 480 | function TThriftListImpl<T>.Extract(const Value: T): T;
|
| 481 | begin
|
| 482 | Result := FList.Extract( Value )
|
| 483 | end;
|
| 484 |
|
| 485 | {$IF CompilerVersion >= 21.0}
|
| 486 | function TThriftListImpl<T>.First: T;
|
| 487 | begin
|
| 488 | Result := FList.First;
|
| 489 | end;
|
| 490 | {$IFEND}
|
| 491 |
|
| 492 | function TThriftListImpl<T>.GetCapacity: Integer;
|
| 493 | begin
|
| 494 | Result := FList.Capacity;
|
| 495 | end;
|
| 496 |
|
| 497 | function TThriftListImpl<T>.GetCount: Integer;
|
| 498 | begin
|
| 499 | Result := FList.Count;
|
| 500 | end;
|
| 501 |
|
| 502 | function TThriftListImpl<T>.GetEnumerator: TEnumerator<T>;
|
| 503 | begin
|
| 504 | Result := FList.GetEnumerator;
|
| 505 | end;
|
| 506 |
|
| 507 | function TThriftListImpl<T>.GetItem(Index: Integer): T;
|
| 508 | begin
|
| 509 | Result := FList[Index];
|
| 510 | end;
|
| 511 |
|
| 512 | function TThriftListImpl<T>.IndexOf(const Value: T): Integer;
|
| 513 | begin
|
| 514 | Result := FList.IndexOf( Value );
|
| 515 | end;
|
| 516 |
|
| 517 | procedure TThriftListImpl<T>.Insert(Index: Integer; const Value: T);
|
| 518 | begin
|
| 519 | FList.Insert( Index, Value);
|
| 520 | end;
|
| 521 |
|
| 522 | procedure TThriftListImpl<T>.InsertRange(Index: Integer;
|
| 523 | const Collection: TEnumerable<T>);
|
| 524 | begin
|
| 525 | FList.InsertRange( Index, Collection );
|
| 526 | end;
|
| 527 |
|
| 528 | procedure TThriftListImpl<T>.InsertRange(Index: Integer;
|
| 529 | const Values: array of T);
|
| 530 | begin
|
| 531 | FList.InsertRange( Index, Values);
|
| 532 | end;
|
| 533 |
|
| 534 | procedure TThriftListImpl<T>.InsertRange(Index: Integer;
|
| 535 | const Collection: IEnumerable<T>);
|
| 536 | begin
|
| 537 | FList.InsertRange( Index, Collection );
|
| 538 | end;
|
| 539 |
|
| 540 | {$IF CompilerVersion >= 21.0}
|
| 541 | function TThriftListImpl<T>.Last: T;
|
| 542 | begin
|
| 543 | Result := FList.Last;
|
| 544 | end;
|
| 545 | {$IFEND}
|
| 546 |
|
| 547 | function TThriftListImpl<T>.LastIndexOf(const Value: T): Integer;
|
| 548 | begin
|
| 549 | Result := FList.LastIndexOf( Value );
|
| 550 | end;
|
| 551 |
|
| 552 | {$IF CompilerVersion >= 21.0}
|
| 553 | procedure TThriftListImpl<T>.Move(CurIndex, NewIndex: Integer);
|
| 554 | begin
|
| 555 | FList.Move( CurIndex, NewIndex);
|
| 556 | end;
|
| 557 | {$IFEND}
|
| 558 |
|
| 559 | function TThriftListImpl<T>.Remove(const Value: T): Integer;
|
| 560 | begin
|
| 561 | Result := FList.Remove( Value );
|
| 562 | end;
|
| 563 |
|
| 564 | procedure TThriftListImpl<T>.Reverse;
|
| 565 | begin
|
| 566 | FList.Reverse;
|
| 567 | end;
|
| 568 |
|
| 569 | procedure TThriftListImpl<T>.SetCapacity(Value: Integer);
|
| 570 | begin
|
| 571 | FList.Capacity := Value;
|
| 572 | end;
|
| 573 |
|
| 574 | procedure TThriftListImpl<T>.SetCount(Value: Integer);
|
| 575 | begin
|
| 576 | FList.Count := Value;
|
| 577 | end;
|
| 578 |
|
| 579 | procedure TThriftListImpl<T>.SetItem(Index: Integer; const Value: T);
|
| 580 | begin
|
| 581 | FList[Index] := Value;
|
| 582 | end;
|
| 583 |
|
| 584 | procedure TThriftListImpl<T>.Sort;
|
| 585 | begin
|
| 586 | FList.Sort;
|
| 587 | end;
|
| 588 |
|
| 589 | procedure TThriftListImpl<T>.Sort(const AComparer: IComparer<T>);
|
| 590 | begin
|
| 591 | FList.Sort;
|
| 592 | end;
|
| 593 |
|
| 594 | function TThriftListImpl<T>.ToArray: TArray<T>;
|
| 595 | {$IF CompilerVersion < 22.0}
|
| 596 | var
|
| 597 | x : T;
|
| 598 | i : Integer;
|
| 599 | {$IFEND}
|
| 600 | begin
|
| 601 | {$IF CompilerVersion < 22.0}
|
| 602 | SetLength(Result, Count);
|
| 603 | i := 0;
|
| 604 | for x in FList do
|
| 605 | begin
|
| 606 | Result[i] := x;
|
| 607 | Inc( i );
|
| 608 | end;
|
| 609 | {$ELSE}
|
| 610 | Result := FList.ToArray;
|
| 611 | {$IFEND}
|
| 612 | end;
|
| 613 |
|
| 614 | procedure TThriftListImpl<T>.TrimExcess;
|
| 615 | begin
|
| 616 | FList.TrimExcess;
|
| 617 | end;
|
| 618 |
|
| 619 | end.
|