94 Commits

Author SHA1 Message Date
Sahnvour
9d6f236728 add fastpath for std.mem.eql and simplify std.hash_map.eqlString
this should also be friendlier to the optimizer
2019-09-03 23:56:04 +02:00
Sahnvour
4c882e731f hash_map: adding a StringHashMap for convenience 2019-08-24 15:30:23 +02:00
Sahnvour
4b5172d287 move autoHash into its own module since it can be used with any hash function implementing a streaming interface 2019-08-04 12:34:37 +02:00
Sahnvour
5bf63bfbf1 make use of hashing streaming interface in autoHash 2019-08-04 12:34:05 +02:00
Marc Tiehuis
83dffc70af Add iterative wyhash api 2019-08-04 12:34:05 +02:00
Sahnvour
5bd407b278 use wyhash in std's hashmap, and improve autoHash to handle more types and behave more correctly 2019-08-04 12:34:05 +02:00
Sahnvour
987c209b40 heap: make one global instance of DirectAllocator
it is now stateless, so the de/init are not necessary anymore
2019-06-22 14:10:53 -04:00
Timon Kruiper
72029c2fc8 Added HashInt to function calls AutoHash\nFixes issue 2669 2019-06-16 14:36:23 -04:00
Josh Wolfe
82ab006e58 HashMap.getValue() 2019-06-13 11:41:34 -04:00
Jonathan Marler
8a2c2da805 Handle putNoClobber errors 2019-06-13 01:56:12 -04:00
Josh Wolfe
80fa871f4a Add HashMap apis that assert the common case
* putNoClobber() for put()
* removeAssertDiscard() for remove()
2019-06-13 00:17:12 -04:00
Ryan Liptak
05e92a51aa Use std.math.isPowerOfTwo across std lib 2019-06-10 16:42:39 -04:00
Andrew Kelley
b735764898
different array literal syntax when inferring the size
old syntax:  []i32{1, 2, 3}
new syntax: [_]i32{1, 2, 3}

closes #1797
2019-06-09 19:26:32 -04:00
Ryan Liptak
8f4229a61c std.HashMap: use std.math.ceilPowerOfTwo 2019-06-05 23:36:51 -07:00
Ryan Liptak
656ac43735 std.HashMap: optimize indexing by avoiding modulo operator
x % y can be optimized if y is a power of two by doing x & (y-1) instead. HashMap already enforces power of two capacity, so we can take advantage of this optimization.
2019-06-05 23:26:48 -07:00
Andrew Kelley
c1793d6106
zig fmt on the standard library 2019-05-12 12:56:01 -04:00
Ryan Liptak
cf8dde2d68 std.HashMap: cleanup ensureCapacity + add test
- Cleaned up some comments
- Removed the "is power of two" check from optimizedCapacity since the * 5 / 3 is unlikely to end up with a power of two, so it's a wasted check the majority of the time
- Made ensureCapacity/ensureCapacityExact increment the modification count if they resize the hash map so that we can catch resizes while iterating, which would likely break the iterator state
2019-05-03 21:15:00 -07:00
Ryan Liptak
13a7b8586a std.HashMap: make ensureCapacityExact private 2019-05-02 17:43:51 -07:00
Ryan Liptak
26591d4f22 std.HashMap: add putAssumeCapacity fn 2019-05-02 17:42:38 -07:00
Ryan Liptak
4d42275d03 std.HashMap: make ensureCapacity optimize for the expected count, add ensureCapacityExact 2019-05-02 17:01:30 -07:00
Ryan Liptak
0afa2d040a make std.HashMap.ensureCapacity round up to the nearest power of two 2019-05-02 00:58:26 -07:00
Ryan Liptak
8b7c59a414 std.HashMap: add public ensureCapacity fn 2019-05-01 23:46:52 -07:00
Ryan Liptak
6a78b315b2 Fix std.HashMap.remove returning incorrect KV
Now returns a copy of the removed kv instead of a pointer to the removed kv. The removed kv gets overwritten when shifting the hash map after the removal, so returning a pointer to it will have another kv's values in it after the return.

This bug had some nasty downstream effects in things like BufSet and BufMap where delete would free a still in-use KV and leave the actually removed KV un-free'd.
2019-04-07 15:47:09 -04:00
Andrew Kelley
d0551db5cd
introduce the enum literal type
see #683
2019-03-24 00:44:18 -04:00
Andrew Kelley
e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05:00
Andrew Kelley
5424b4320d
remove namespace type; files are empty structs
closes #1047
2019-02-28 10:11:32 -05:00
Andrew Kelley
6769183a9d
fix implicit cast error unions with non-optional to optional pointer
and update self hosted compiler for C pointers

See #1059
2019-02-14 15:48:28 -05:00
Andrew Kelley
c2db077574
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
545064c1d9
introduce vector type for SIMD
See #903

 * create with `@Vector(len, ElemType)`
 * only wrapping addition is implemented

This feature is far from complete; this is only the beginning.
2019-01-30 23:39:25 -05:00
Jimmi Holst Christensen
f74320d56d Implemented getOrPutValue which wraps getOrPut 2018-11-29 09:10:15 +01:00
Jimmi Holst Christensen
8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00
Jimmi Holst Christensen
378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00
Andrew Kelley
c06a61e9bf
remove this. add @This().
closes #1283
2018-09-13 16:34:33 -04:00
Andrew Kelley
3173c90f14 macos stack traces: read debug info sections from .o files 2018-08-23 23:08:34 -04:00
Andrew Kelley
1a28f09684 fix hash map test 2018-08-07 00:54:19 -04:00
Andrew Kelley
97be8debab std.HashMap.autoHash: use xor instead of wrapping mult 2018-08-06 19:09:22 -04:00
Andrew Kelley
5dfcd09e49 self-hosted: watch files and trigger a rebuild 2018-08-03 17:22:17 -04:00
Andrew Kelley
e3ae2cfb52 add std.event.RwLock and a few more std changes
* add std.event.RwLock and std.event.RwLocked
 * std.debug.warn does its printing locked
 * add std.Mutex, however it's currently implemented as a spinlock
 * rename std.event.Group.cancelAll to std.event.Group.deinit and change
   the docs and assumptions.
 * add std.HashMap.clone
2018-08-01 16:26:37 -04:00
Andrew Kelley
42ba06133a std.Hashmap - don't use catch unreachable in tests 2018-07-09 10:44:06 -04:00
Andrew Kelley
ec1b6f6673
breaking syntax change: ??x to x.? (#1095)
See #1023

This also renames Nullable/Maybe to Optional
2018-06-09 23:42:14 -04:00
Andrew Kelley
fcbb7426fa use * for pointer type instead of &
See #770

To help automatically translate code, see the
zig-fmt-pointer-reform-2 branch.

This will convert all & into *. Due to the syntax
ambiguity (which is why we are making this change),
even address-of & will turn into *, so you'll have
to manually fix thes instances. You will be guaranteed
to get compile errors for them - expected 'type', found 'foo'
2018-05-31 17:28:07 -04:00
Andrew Kelley
ea58f4a5a9 run zig fmt on the codebase 2018-05-30 16:09:11 -04:00
Andrew Kelley
4787127cf6 partial conversion to post-fix pointer deref using zig fmt 2018-05-10 00:29:49 -04:00
Jimmi Holst Christensen
87c0060e81 Made container methods that can be const, const 2018-05-04 23:48:14 +02:00
Braedon
e907c5cab9 Unified API 2018-05-03 23:54:33 +10:00
Andrew Kelley
58c6424d4f simplify and fix BufMap logic 2018-04-11 00:32:42 -04:00
Andrew Kelley
40dbcd09da fix type_is_codegen_pointer being used incorrectly
The names of these functions should probably change, but at least
the semantics are correct now:
 * type_is_codegen_pointer - the type is either a fn, ptr, or promise
 * get_codegen_ptr_type -
   - ?&T and &T returns &T
   - ?promise and promise returns promise
   - ?fn()void and fn()void returns fn()void
   - otherwise returns nullptr
2018-02-23 12:49:21 -05:00
Andrew Kelley
5f518dbeb9 *WIP* error sets converting std lib 2018-01-31 22:48:40 -05:00
Andrew Kelley
3671582c15 syntax: functions require return type. remove ->
The purpose of this is:

 * Only one way to do things
 * Changing a function with void return type to return a possible
   error becomes a 1 character change, subtly encouraging
   people to use errors.

See #632

Here are some imperfect sed commands for performing this update:

remove arrow:

```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```

add void:

```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```

Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-25 04:10:11 -05:00
Andrew Kelley
5aefabe045 docgen: validate See Also sections
See #465
2018-01-17 00:22:53 -05:00