Răsfoiți Sursa

More uint consistency

Billy Barrow 4 zile în urmă
părinte
comite
76b13dcde2

+ 1 - 1
src/lib/DataStructures/Buffer.vala

@@ -8,7 +8,7 @@ namespace Invercargill.DataStructures {
         private SafeWriteFunc<T>? safe_write;
 
         public override Tracker<T> get_tracker () {
-            int pos = 0;
+            uint pos = 0;
             var read = safe_read;
             if(read == null) {
                 read = (a, i) => a[i];

+ 6 - 6
src/lib/DataStructures/HashSet.vala

@@ -11,9 +11,9 @@ namespace Invercargill.DataStructures {
 
         private HashSetItem<T>* tombstone;
         private HashSetItem<T>*[] buckets;
-        private int n_items = 0;
-        private int n_buckets = 16;
-        private int n_collissions = 0;
+        private uint n_items = 0;
+        private uint n_buckets = 16;
+        private uint n_collissions = 0;
         private SafeReadFunc<T>? safe_read;
         private SafeWriteFunc<T>? safe_write;
         private HashDelegate<T> hash_func;
@@ -53,7 +53,7 @@ namespace Invercargill.DataStructures {
             buckets = new HashSetItem<T>*[n_buckets];
             n_collissions = 0;
 
-            for(var i = 0; i < old_buckets.length; i++) {
+            for(uint i = 0; i < old_buckets.length; i++) {
                 var bucket = old_buckets[i];
                 if(bucket == null || bucket == tombstone) {
                     continue;
@@ -86,7 +86,7 @@ namespace Invercargill.DataStructures {
         }
 
         public override Tracker<T> get_tracker () {
-            return Iterate.range(0, n_buckets)
+            return Iterate.range(0, (int)n_buckets)
                 .where(i => buckets[i] != null && buckets[i] != tombstone)
                 .select<T>(i => buckets[i]->item)
                 .get_tracker();
@@ -194,7 +194,7 @@ namespace Invercargill.DataStructures {
         }
 
         private void delete_items() {
-            for(int i = 0; i < buckets.length; i++) {
+            for(uint i = 0; i < buckets.length; i++) {
                 if(buckets[i] != null && buckets[i] != tombstone)
                 delete buckets[i];
             }

+ 1 - 1
src/lib/DataStructures/ImmutableBuffer.vala

@@ -7,7 +7,7 @@ namespace Invercargill.DataStructures {
         private SafeReadFunc<T>? safe_read;
 
         public override Tracker<T> get_tracker () {
-            int pos = 0;
+            uint pos = 0;
             var read = safe_read;
             if(read == null) {
                 read = (a, i) => a[i];

+ 8 - 8
src/lib/DataStructures/PriorityQueue.vala

@@ -16,7 +16,7 @@ namespace Invercargill.DataStructures {
 
         public override uint? peek_count() {
             mutex.lock();
-            var count = (int)items.length;
+            var count = items.length;
             mutex.unlock();
             return count;
         }
@@ -42,7 +42,7 @@ namespace Invercargill.DataStructures {
             items.add(queue_item);
             
             // Bubble up to maintain heap property
-            bubble_up((int)(items.length - 1));
+            bubble_up(items.length - 1);
 
             cond.broadcast();
             mutex.unlock();
@@ -91,10 +91,10 @@ namespace Invercargill.DataStructures {
             return result;
         }
 
-        private void bubble_up(int index) {
+        private void bubble_up(uint index) {
             if(index == 0) return;
             
-            int parent = (index - 1) / 2;
+            uint parent = (index - 1) / 2;
             var current = items.get(index);
             var parent_item = items.get(parent);
             
@@ -106,10 +106,10 @@ namespace Invercargill.DataStructures {
             }
         }
 
-        private void bubble_down(int index) {
-            int left = 2 * index + 1;
-            int right = 2 * index + 2;
-            int smallest = index;
+        private void bubble_down(uint index) {
+            uint left = 2 * index + 1;
+            uint right = 2 * index + 2;
+            uint smallest = index;
             
             if(left < items.length) {
                 var left_item = items.get(left);

+ 1 - 1
src/lib/DataStructures/RingBuffer.vala

@@ -8,7 +8,7 @@ namespace Invercargill.DataStructures {
         private SafeWriteFunc<T>? safe_write;
 
         public override Tracker<T> get_tracker () {
-            int pos = 0;
+            uint pos = 0;
             return new LambdaTracker<T> (() => array.length > 0, () => safe_read(array, pos++ % array.length));
         }
         public override uint? peek_count () {

+ 1 - 1
src/lib/DataStructures/Series.vala

@@ -14,7 +14,7 @@ namespace Invercargill.DataStructures {
 
         internal SeriesItem<T>* root;
         internal SeriesItem<T>* end;
-        private int n_items = 0;
+        private uint n_items = 0;
 
         public Series() {}
 

+ 1 - 1
src/lib/DataStructures/SortedSeries.vala

@@ -55,7 +55,7 @@ namespace Invercargill.DataStructures {
         private SeriesNode<T>* nil;
         private RWLock rw_lock;
         private CompareDelegate<T> comparitor;
-        private int n_items;
+        private uint n_items;
 
         public override uint length { get { return n_items; }}
 

+ 8 - 11
src/lib/DataStructures/Vector.vala

@@ -3,12 +3,12 @@ namespace Invercargill.DataStructures {
     public class Vector<T> : Enumerable<T>, Lot<T>, ReadOnlyCollection<T>, ReadOnlyAddressable<T>, Collection<T>, Addressable<T>, AddressableCollection<T> {
 
         private T[] array;
-        private int n_items = 0;
+        private uint n_items = 0;
         private SafeReadFunc<T>? safe_read;
         private SafeWriteFunc<T>? safe_write;
         private RWLock rw_lock;
 
-        private const int INITIAL_SIZE = 2;
+        private const uint INITIAL_SIZE = 2;
 
         public Vector() {
             rw_lock = RWLock();
@@ -42,12 +42,12 @@ namespace Invercargill.DataStructures {
             rw_lock.reader_lock();
             var a2 = new T[n_items];
             if(safe_write != null) {
-                for(var i = 0; i < n_items; i++) {
+                for(uint i = 0; i < n_items; i++) {
                     safe_write(a2, i, array_read(i));
                 }
             }
             else {
-                for(var i = 0; i < n_items; i++) {
+                for(uint i = 0; i < n_items; i++) {
                     a2[i] = array[i];
                 }
             }
@@ -121,7 +121,7 @@ namespace Invercargill.DataStructures {
             throw e;
         }
 
-        private void ensure_room(int items) {
+        private void ensure_room(uint items) {
             if(array.length <= n_items + items) {
                 array.resize(array.length * 2);
             }
@@ -150,10 +150,7 @@ namespace Invercargill.DataStructures {
         private IndexError? remove_internal(uint index) {
             IndexError? e = null;
             rw_lock.writer_lock();
-            if(index < 0) {
-                e = new IndexError.INDEX_EXCEEDS_LOWER_BOUNDS("Index is less than 0");
-            }
-            else if(index >= n_items) {
+            if(index >= n_items) {
                 e = new IndexError.INDEX_EXCEEDS_UPPER_BOUNDS(@"Tried to set index $(index) on a vector with $(n_items) item(s)");
             }
             else {
@@ -222,12 +219,12 @@ namespace Invercargill.DataStructures {
         }
 
         public uint? first_index_of(PredicateDelegate<T> predicate) {
-            var i = -1;
+            var i = 0;
             foreach (var item in this) {
-                i++;
                 if(predicate(item)) {
                     return i;
                 }
+                i++;
             }
             return null;
         }

+ 1 - 1
src/lib/Interfaces/AddressableBytes.vala

@@ -173,7 +173,7 @@ namespace Invercargill {
         }
 
         private void set_data(uint index, uint8[] data) throws IndexError {
-            for(int i = 0; i < data.length; i++) {
+            for(uint i = 0; i < data.length; i++) {
                 this[i + index] = data[i];
             }
         }

+ 2 - 2
src/lib/Interfaces/BinaryData.vala

@@ -28,11 +28,11 @@ namespace Invercargill {
             return new ByteBuffer.from_enumerable(this);
         }
 
-        public virtual BinaryData slice(int start, int end) {
+        public virtual BinaryData slice(uint start, uint end) {
             return skip(start).take(end-start).assert_promotion<BinaryData>();
         }
 
-        public virtual ByteBuffer read(int start, int length) {
+        public virtual ByteBuffer read(uint start, uint length) {
             return new ByteBuffer.from_enumerable(skip(start).take(length));
         }
 

+ 9 - 9
src/lib/Interfaces/ReadOnlyAddressableBytes.vala

@@ -11,7 +11,7 @@ namespace Invercargill {
     [GenericAccessors]
     public interface ReadOnlyAddressableBytes : ReadOnlyAddressable<uint8>, Equatable<Enumerable<uint8>>, BinaryData, Hashable  {
 
-        public virtual int64? get_int64(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual int64? get_int64(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(int64));
             int64 value = 0;
             int64 val = 0;
@@ -30,7 +30,7 @@ namespace Invercargill {
             return val;           
         }
 
-        public virtual uint64? get_uint64(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual uint64? get_uint64(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(uint64));
             uint64 value = 0;
             uint64 val = 0;
@@ -50,7 +50,7 @@ namespace Invercargill {
         }
 
 
-        public virtual int32? get_int32(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual int32? get_int32(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(int32));
             int32 value = 0;
             int32 val = 0;
@@ -69,7 +69,7 @@ namespace Invercargill {
             return val;           
         }
 
-        public virtual uint32? get_uint32(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual uint32? get_uint32(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(uint32));
             uint32 value = 0;
             uint32 val = 0;
@@ -88,7 +88,7 @@ namespace Invercargill {
             return val;           
         }
 
-        public virtual int16? get_int16(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual int16? get_int16(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(int16));
             int16 value = 0;
             int16 val = 0;
@@ -107,7 +107,7 @@ namespace Invercargill {
             return val;           
         }
 
-        public virtual uint16? get_uint16(int index, Endianness endianness = Endianness.Native) throws IndexError {
+        public virtual uint16? get_uint16(uint index, Endianness endianness = Endianness.Native) throws IndexError {
             var data = get_slice(index, sizeof(uint16));
             uint16 value = 0;
             uint16 val = 0;
@@ -126,14 +126,14 @@ namespace Invercargill {
             return val;           
         }
 
-        public virtual int8? get_int8(int index) throws IndexError {
+        public virtual int8? get_int8(uint index) throws IndexError {
             var data = get_slice(index, sizeof(int8));
             int8 value = 0;
             Memory.copy(&value, data, sizeof(int8));
             return value;           
         }
 
-        public virtual uint8? get_uint8(int index) throws IndexError {
+        public virtual uint8? get_uint8(uint index) throws IndexError {
             var data = get_slice(index, sizeof(uint8));
             uint8 value = 0;
             Memory.copy(&value, data, sizeof(uint8));
@@ -142,7 +142,7 @@ namespace Invercargill {
 
         private uint8[] get_slice(uint index, ulong size) throws IndexError {
             var slice = new uint8[size];
-            for(int i = 0; i < size; i++) {
+            for(uint i = 0; i < size; i++) {
                 slice[i] = this[i + index];
             }
             return slice;