about summary refs log tree commit diff
path: root/src/libstd/vec.rs
AgeCommit message (Collapse)AuthorLines
2014-06-05std: Recreate a `collections` moduleAlex Crichton-1903/+0
As with the previous commit with `librand`, this commit shuffles around some `collections` code. The new state of the world is similar to that of librand: * The libcollections crate now only depends on libcore and liballoc. * The standard library has a new module, `std::collections`. All functionality of libcollections is reexported through this module. I would like to stress that this change is purely cosmetic. There are very few alterations to these primitives. There are a number of notable points about the new organization: * std::{str, slice, string, vec} all moved to libcollections. There is no reason that these primitives shouldn't be necessarily usable in a freestanding context that has allocation. These are all reexported in their usual places in the standard library. * The `hashmap`, and transitively the `lru_cache`, modules no longer reside in `libcollections`, but rather in libstd. The reason for this is because the `HashMap::new` contructor requires access to the OSRng for initially seeding the hash map. Beyond this requirement, there is no reason that the hashmap could not move to libcollections. I do, however, have a plan to move the hash map to the collections module. The `HashMap::new` function could be altered to require that the `H` hasher parameter ascribe to the `Default` trait, allowing the entire `hashmap` module to live in libcollections. The key idea would be that the default hasher would be different in libstd. Something along the lines of: // src/libstd/collections/mod.rs pub type HashMap<K, V, H = RandomizedSipHasher> = core_collections::HashMap<K, V, H>; This is not possible today because you cannot invoke static methods through type aliases. If we modified the compiler, however, to allow invocation of static methods through type aliases, then this type definition would essentially be switching the default hasher from `SipHasher` in libcollections to a libstd-defined `RandomizedSipHasher` type. This type's `Default` implementation would randomly seed the `SipHasher` instance, and otherwise perform the same as `SipHasher`. This future state doesn't seem incredibly far off, but until that time comes, the hashmap module will live in libstd to not compromise on functionality. * In preparation for the hashmap moving to libcollections, the `hash` module has moved from libstd to libcollections. A previously snapshotted commit enables a distinct `Writer` trait to live in the `hash` module which `Hash` implementations are now parameterized over. Due to using a custom trait, the `SipHasher` implementation has lost its specialized methods for writing integers. These can be re-added backwards-compatibly in the future via default methods if necessary, but the FNV hashing should satisfy much of the need for speedier hashing. A list of breaking changes: * HashMap::{get, get_mut} no longer fails with the key formatted into the error message with `{:?}`, instead, a generic message is printed. With backtraces, it should still be not-too-hard to track down errors. * The HashMap, HashSet, and LruCache types are now available through std::collections instead of the collections crate. * Manual implementations of hash should be parameterized over `hash::Writer` instead of just `Writer`. [breaking-change]
2014-06-03std: Remove generics from Option::expectAlex Crichton-1/+1
This commit removes the <M: Any + Send> type parameter from Option::expect in favor of just taking a hard-coded `&str` argument. This allows this function to move into libcore. Previous code using strings with `expect` will continue to work, but code using this implicitly to transmit task failure will need to unwrap manually with a `match` statement. [breaking-change] Closes #14008
2014-06-01std: Drop Total from Total{Eq,Ord}Alex Crichton-5/+5
This completes the last stage of the renaming of the comparison hierarchy of traits. This change renames TotalEq to Eq and TotalOrd to Ord. In the future the new Eq/Ord will be filled out with their appropriate methods, but for now this change is purely a renaming change. [breaking-change]
2014-05-30std: Rename {Eq,Ord} to Partial{Eq,Ord}Alex Crichton-5/+5
This is part of the ongoing renaming of the equality traits. See #12517 for more details. All code using Eq/Ord will temporarily need to move to Partial{Eq,Ord} or the Total{Eq,Ord} traits. The Total traits will soon be renamed to {Eq,Ord}. cc #12517 [breaking-change]
2014-05-27std: Rename strbuf operations to stringRicho Healey-2/+2
[breaking-change]
2014-05-27std: Remove String's to_ownedRicho Healey-6/+7
2014-05-24core: rename strbuf::StrBuf to string::StringRicho Healey-2/+2
[breaking-change]
2014-05-22libstd: Remove `~str` from all `libstd` modules except `fmt` and `str`.Patrick Walton-4/+4
2014-05-20core: Stabilize the mem moduleAlex Crichton-7/+9
Excluding the functions inherited from the cast module last week (with marked stability levels), these functions received the following treatment. * size_of - this method has become #[stable] * nonzero_size_of/nonzero_size_of_val - these methods have been removed * min_align_of - this method is now #[stable] * pref_align_of - this method has been renamed without the `pref_` prefix, and it is the "default alignment" now. This decision is in line with what clang does (see url linked in comment on function). This function is now #[stable]. * init - renamed to zeroed and marked #[stable] * uninit - marked #[stable] * move_val_init - renamed to overwrite and marked #[stable] * {from,to}_{be,le}{16,32,64} - all functions marked #[stable] * swap/replace/drop - marked #[stable] * size_of_val/min_align_of_val/align_of_val - these functions are marked #[unstable], but will continue to exist in some form. Concerns have been raised about their `_val` prefix. [breaking-change]
2014-05-15Make Vec.truncate() resilient against failure in DropKevin Ballard-5/+40
If a vector element fails in Drop, Vec needs to make sure it doesn't try to re-drop any elements it already dropped.
2014-05-11core: Remove the cast moduleAlex Crichton-34/+48
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-10vec: factor out some deallocation codeDaniel Micay-9/+12
2014-05-10vec: move some code inside alloc_or_reallocDaniel Micay-7/+5
2014-05-10fix Vec<ZeroSizeType>Daniel Micay-2/+15
2014-05-10initial port of the exchange allocator to jemallocDaniel Micay-1/+1
In stage0, all allocations are 8-byte aligned. Passing a size and alignment to free is not yet implemented everywhere (0 size and 8 align are used as placeholders). Fixing this is part of #13994. Closes #13616
2014-05-10use jemalloc to implement Vec<T>Daniel Micay-27/+46
2014-05-08Move partition/partitioned/concat/connect tests back into sliceKevin Ballard-26/+4
There was no reason to remove them from slice. They're testing methods defined in slice, so that's where they belong. Leave vec with copies of the partition/partitioned tests because it has its own implementation of those methods.
2014-05-08Add a mechanism to convert from Vec<T> to ~[T]Kevin Ballard-1/+73
Add a new trait FromVec with one self-less method from_vec(). This is kind of like FromIterator, but it consumes a Vec<T>. It's only implemented for ~[T], but the idea is post-DST it can be implemented for any Boxed<[T]>.
2014-05-08Handle fallout for vector additionKevin Ballard-1/+11
Adding two vectors now results in a Vec<T> instead of a ~[T]. Implement Add on Vec<T>.
2014-05-08Move slice::raw::from_buf_raw() to vec::raw::from_buf()Kevin Ballard-1/+36
Change from_buf_raw() to return a Vec<T> instead of a ~[T]. As such, it belongs in vec, in the newly-created vec::raw module.
2014-05-08Rename slice::unzip() to vec::unzip()Kevin Ballard-0/+33
unzip() has nothing to do with slices, so it belongs in vec.
2014-05-08More fallout from removing FromIterator on ~[T]Kevin Ballard-0/+38
A few methods in slice that used to return ~[T] now return Vec<T>: - VectorVector.concat/connect_vec() returns Vec<T> - slice::unzip() returns (Vec<T>, Vec<U>) - ImmutableCloneableVector.partitioned() returns (Vec<T>, Vec<T>) - OwnedVector.partition() returns (Vec<T>, Vec<T>)
2014-05-07core: Move Option::expect to libstd from libcoreAlex Crichton-1/+1
See #14008 for more details
2014-05-07core: Inherit non-allocating slice functionalityAlex Crichton-0/+1
This commit adds a new trait, MutableVectorAllocating, which represents functions on vectors which can allocate. This is another extension trait to slices which should be removed once a lang item exists for the ~ allocation.
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-3/+3
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-2/+2
2014-05-01remove leftover obsolete string literalsDaniel Micay-3/+3
2014-04-28Fixed typo in std::vecAdolfo Ochagavía-1/+1
2014-04-21Fix misspellings in comments.Joseph Crail-2/+2
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-6/+6
2014-04-18std: Make ~[T] no longer a growable vectorAlex Crichton-19/+19
This removes all resizability support for ~[T] vectors in preparation of DST. The only growable vector remaining is Vec<T>. In summary, the following methods from ~[T] and various functions were removed. Each method/function has an equivalent on the Vec type in std::vec unless otherwise stated. * slice::OwnedCloneableVector * slice::OwnedEqVector * slice::append * slice::append_one * slice::build (no replacement) * slice::bytes::push_bytes * slice::from_elem * slice::from_fn * slice::with_capacity * ~[T].capacity() * ~[T].clear() * ~[T].dedup() * ~[T].extend() * ~[T].grow() * ~[T].grow_fn() * ~[T].grow_set() * ~[T].insert() * ~[T].pop() * ~[T].push() * ~[T].push_all() * ~[T].push_all_move() * ~[T].remove() * ~[T].reserve() * ~[T].reserve_additional() * ~[T].reserve_exect() * ~[T].retain() * ~[T].set_len() * ~[T].shift() * ~[T].shrink_to_fit() * ~[T].swap_remove() * ~[T].truncate() * ~[T].unshift() * ~str.clear() * ~str.set_len() * ~str.truncate() Note that no other API changes were made. Existing apis that took or returned ~[T] continue to do so. [breaking-change]
2014-04-16Make Vec::clone and slice::to_owned failure-safeJames Miller-7/+4
2014-04-16Improve the copying code for slices and VecJames Miller-1/+20
2014-04-11std: Fix iteration over vectors of 0-size valuesAlex Crichton-2/+46
Previously, all slices derived from a vector whose values were of size 0 had a null pointer as the 'data' pointer on the slice. This caused first pointer to be yielded during iteration to always be the null pointer. Due to the null pointer optimization, this meant that the first return value was None, instead of Some(&T). This commit changes slice construction from a Vec instance to use a base pointer of 1 if the values have zero size. This means that the iterator will never return null, and the iteration will proceed appropriately. Closes #13467
2014-04-10libstd: Implement `StrBuf`, a new string buffer type like `Vec`, andPatrick Walton-1/+2
port all code over to use it.
2014-04-08Register new snapshotsAlex Crichton-0/+1
2014-04-04Added grow_fn and retain to VecMichael Darakananda-1/+64
2014-04-03std: override clone_from for Vec.Huon Wilson-4/+52
A vector can reuse its allocation (and the allocations/resources of any contained values) when cloning into an already-instantiated vector, so we might as well do so.
2014-04-01Reimplement Vec::push_all* with .extendStepan Koltsov-6/+2
It is shorter and also fixes missed reserve call.
2014-04-01Vec::reserve_exact should not shrinkStepan Koltsov-1/+1
reserve_exact should not shrink according to documentation.
2014-03-31std: Switch field privacy as necessaryAlex Crichton-5/+5
2014-03-31auto merge of #13221 : thestinger/rust/append, r=alexcrichtonbors-32/+32
These were only free functions on `~[T]` because taking self by-value used to be broken.
2014-03-31vec: convert `append` and `append_one` to methodsDaniel Micay-32/+32
These were only free functions on `~[T]` because taking self by-value used to be broken.
2014-03-30Rename `from_iterator` to `from_iter` for consistency.Brian Anderson-1/+1
2014-03-30Removed deprecated functions `map` and `flat_map` for vectors and slices.Marvin Löbel-7/+0
2014-03-25Changed `iter::Extendable` and `iter::FromIterator` to take a `Iterator` by ↵Marvin Löbel-6/+6
value
2014-03-24comm: Implement synchronous channelsAlex Crichton-7/+2
This commit contains an implementation of synchronous, bounded channels for Rust. This is an implementation of the proposal made last January [1]. These channels are built on mutexes, and currently focus on a working implementation rather than speed. Receivers for sync channels have select() implemented for them, but there is currently no implementation of select() for sync senders. Rust will continue to provide both synchronous and asynchronous channels as part of the standard distribution, there is no intent to remove asynchronous channels. This flavor of channels is meant to provide an alternative to asynchronous channels because like green tasks, asynchronous channels are not appropriate for all situations. [1] - https://mail.mozilla.org/pipermail/rust-dev/2014-January/007924.html
2014-03-23auto merge of #13096 : sstewartgallus/rust/cleanup-test-warnings, r=huonwbors-1/+0
2014-03-23This commit cleans up a few test warningsSteven Stewart-Gallus-1/+0
2014-03-23std: remove the `equals` method from `TotalEq`.Huon Wilson-6/+1
`TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.)