# Differences

This shows you the differences between two versions of the page.

ada.containers.vectors [2012/01/24 07:53] thomaslocke [Vectors.Find_Index] |
ada.containers.vectors [2012/01/24 08:10] (current) thomaslocke [Equality] |
||
---|---|---|---|

Line 2065: | Line 2065: | ||

==== Vectors.Find ==== | ==== Vectors.Find ==== | ||

- | On the [[Vectors.Find|Example Source]] page, you will find the //Find_Index// example from above, modified to work with //Find//. These two functions are so alike in usage and functionality, that it would be a complete waste of space to do any further explaining. So all you get is the specification and the [[Vectors.Find|Example Source]]. | + | On the [[Vectors.Find|Vectors.Find Example Source]] page, you will find the //Find_Index// example from above, modified to work with //Find//. These two functions are so alike in usage and functionality, that it would be a complete waste of space to do any further explaining. So all you get is the specification and the [[Vectors.Find|Vectors.Find Example Source]]. |

Here's the specification for //Find//: | Here's the specification for //Find//: | ||

Line 2076: | Line 2076: | ||

</code> | </code> | ||

- | [[Vectors.Find|Example Source]] | + | [[Vectors.Find|Vectors.Find Example Source]] |

==== Vectors.Reverse_Find_Index ==== | ==== Vectors.Reverse_Find_Index ==== | ||

Line 2091: | Line 2091: | ||

</code> | </code> | ||

- | [[Vectors.Reverse_Find_Index|Example Source]] | + | [[Vectors.Reverse_Find_Index|Vectors.Reverse_Find_Index Example Source]] |

==== Vectors.Reverse_Find ==== | ==== Vectors.Reverse_Find ==== | ||

Line 2106: | Line 2106: | ||

</code> | </code> | ||

- | [[Vectors.Reverse_Find|Example Source]] | + | [[Vectors.Reverse_Find|Vectors.Reverse_Find Example Source]] |

==== Vectors.Contains ==== | ==== Vectors.Contains ==== | ||

Line 2150: | Line 2150: | ||

Found! | Found! | ||

- | As stated earlier, //Contains// searches the vector from start to end, but that might not be the best solution. Sometimes you know a piece of data is placed near the end of the vector, if it's there at all. In such a case, a //Contains// function that searches in reverse is what we're looking for. One such would be easy to do: [[Vectors.Reverse_Contains|Example Source]]. With //Reverse_// editions available for the two //Find// functions, I find it odd that there isn't a Reverse_Contains function available. Luckily, as the preceding source shows, it is very easy to add it yourself. | + | As stated earlier, //Contains// searches the vector from start to end, but that might not be the best solution. Sometimes you know a piece of data is placed near the end of the vector, if it's there at all. In such a case, a //Contains// function that searches in reverse is what we're looking for. One such would be easy to do: [[Vectors.Reverse_Contains|Vectors.Reverse_Contains Example Source]]. With //Reverse_// editions available for the two //Find// functions, I find it odd that there isn't a Reverse_Contains function available. Luckily, as the preceding source shows, it is very easy to add it yourself. |

- | [[Vectors.Contains|Example Source]] | + | [[Vectors.Contains|Vectors.Contains Example Source]] |

==== Vectors.Has_Element ==== | ==== Vectors.Has_Element ==== | ||

Line 2208: | Line 2208: | ||

And the output is: | And the output is: | ||

- | -1 No Element! | + | <code> |

- | 9 Element! | + | -1 No Element! |

- | -1 No Element! | + | 9 Element! |

- | 8 Element! | + | -1 No Element! |

+ | 8 Element! | ||

+ | </code> | ||

I've honestly never had any use for //Has_Element// while working with vectors, but that's probably because I hardly ever use cursors with vectors. With [[Ada.Containers.Doubly_Linked_Lists]] it is a different story though, as the only means of navigating a doubly linked list is by using cursors. | I've honestly never had any use for //Has_Element// while working with vectors, but that's probably because I hardly ever use cursors with vectors. With [[Ada.Containers.Doubly_Linked_Lists]] it is a different story though, as the only means of navigating a doubly linked list is by using cursors. | ||

- | [[Vectors.Has_Element|Example Source]] | + | [[Vectors.Has_Element|Vectors.Has_Element Example Source]] |

===== From index to cursor, and vice versa ===== | ===== From index to cursor, and vice versa ===== | ||

Line 2263: | Line 2265: | ||

The important thing to take away from this example, is the //No_Element// part. If the given //Index// is out of range, then //No_Element// is returned. | The important thing to take away from this example, is the //No_Element// part. If the given //Index// is out of range, then //No_Element// is returned. | ||

- | [[Vectors.To_Cursor|Example Source]] | + | [[Vectors.To_Cursor|Vectors.To_Cursor Example Source]] |

==== Vectors.To_Index ==== | ==== Vectors.To_Index ==== | ||

Line 2296: | Line 2298: | ||

This is not exactly rocket science, but it is worth noting that //No_Element// is "transformed" into //No_Index// when //To_Index// is called on a cursor which point at //No_Element//. | This is not exactly rocket science, but it is worth noting that //No_Element// is "transformed" into //No_Index// when //To_Index// is called on a cursor which point at //No_Element//. | ||

- | [[Vectors.To_Index|Example Source]] | + | [[Vectors.To_Index|Vectors.To_Index Example Source]] |

===== Vectors.Generic_Sorting ===== | ===== Vectors.Generic_Sorting ===== | ||

Line 2357: | Line 2359: | ||

And there you have it: A perfectly sorted //quotes.txt// file. It just doesn't get any simpler than that. | And there you have it: A perfectly sorted //quotes.txt// file. It just doesn't get any simpler than that. | ||

- | [[Vectors.Generic_Sorting.Sort|Example Source]] | + | [[Vectors.Generic_Sorting.Sort|Vectors.Generic_Sorting.Sort Example Source]] |

==== Generic_Sorting.Is_Sorted ==== | ==== Generic_Sorting.Is_Sorted ==== | ||

Line 2408: | Line 2410: | ||

In case of large vectors, this is not very efficient. Given that, you should of course only use //Is_Sorted// if it's absolutely necessary. | In case of large vectors, this is not very efficient. Given that, you should of course only use //Is_Sorted// if it's absolutely necessary. | ||

- | [[Vectors.Generic_Sorting.Is_Sorted|Example Source]] | + | [[Vectors.Generic_Sorting.Is_Sorted|Vectors.Generic_Sorting.Is_Sorted Example Source]] |

==== Generic_Sorting.Merge ==== | ==== Generic_Sorting.Merge ==== | ||

Line 2482: | Line 2484: | ||

When using //Merge// it is very important to remember this: Both the //Target// and //Source// vectors **must** be sorted prior to the //Merge// call, else you'll end up with an un-sorted vector as the result. (If that is all you want, then it's probably faster to use one of the following procedures: [[Ada.Containers.Vectors#Vectors.Append | Append]], [[Ada.Containers.Vectors#Vectors.Insert | Insert]], [[Ada.Containers.Vectors#Vectors.Prepend | Prepend]]. Or you could simply use the //&// function to get the job done.) | When using //Merge// it is very important to remember this: Both the //Target// and //Source// vectors **must** be sorted prior to the //Merge// call, else you'll end up with an un-sorted vector as the result. (If that is all you want, then it's probably faster to use one of the following procedures: [[Ada.Containers.Vectors#Vectors.Append | Append]], [[Ada.Containers.Vectors#Vectors.Insert | Insert]], [[Ada.Containers.Vectors#Vectors.Prepend | Prepend]]. Or you could simply use the //&// function to get the job done.) | ||

- | [[Vectors.Generic_Sorting.Merge|Example Source]] | + | [[Vectors.Generic_Sorting.Merge|Vectors.Generic_Sorting.Merge Example Source]] |

===== Concatenate using the & operator ===== | ===== Concatenate using the & operator ===== | ||

Line 2630: | Line 2632: | ||

If you care about performance, it is probably best to avoid using the "&" functions. As the simple benchmark shows, there are faster ways to concatenate vectors and/or vector elements than using "&". | If you care about performance, it is probably best to avoid using the "&" functions. As the simple benchmark shows, there are faster ways to concatenate vectors and/or vector elements than using "&". | ||

- | [[The|& operator Example Source]] | + | [[The & operator Example Source|The & operator Example Source]] |

===== Equality ===== | ===== Equality ===== | ||

Line 2667: | Line 2669: | ||

This is of course as expected. | This is of course as expected. | ||

- | [[Equality|Example Source]] | + | [[Equality|Equality Example Source]] |