Kotlin lists have the useful property indices that provides the range of valid indices.
But according to https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/indices.html it is actually a property not just of lists but of collections. Tried an experiment and sure enough, a set also has this property.
But sets cannot be indexed by integer the way lists can. So it's not meaningful to talk about the indices of a set.
Given that, why is it a property of collections in general rather than just lists (and arrays)?
But sets cannot be indexed by integer the way lists can. So it's not meaningful to talk about the indices of a set.
Having the ability the randomly access an element by index is one of the usages of indices. But you could be using them as integer keys. Basically they are defined as a integer range mapping to elements, so this works for any collection. In code, it is simply implemented as [0..size)
It’s not very clear how idProperty is used in the data store when building a data model. The documentation says “If the store has a single primary key, this indicates the property to use as the identity property. The values of this property should be unique. This defaults to "id".
Is this assuming the schema from which the model is based, has a mostly flat structure? For example an array of objects – each with an identity property?
What if the schema is not a simple array but has more complex structure starting from a single object that contains several sub levels of properties within properties. OR is just multiple arrays on the same level where each group of arrays identify property are independent of one another?
A store is an extension of a collection.
A collection is the interface for a collection of items (your obect with a potentially complex schema).
You can use Custom Querying on a collection to define special queries to find your data with any subset of properties.
In short, yes you can querying your data even if it has a custom schema but you need to define a Custom Querying.
More info can be found here at the end of the article: https://github.com/SitePen/dstore/blob/master/docs/Collection.md
It is my understanding that a data structure is essentially a blueprint which contains all the information necessary to create a final product according to its specification, and a data type is a physical implementation or realization of that design (quite similar to the difference between a genotype and phenotype, from biology).
When it comes to object-oriented oriented programming, would it be accurate to say that an abstract class or interface is a data structure, because it contains a set of values and declared behaviors, and that a class which implements that abstract class or interface is a data type, because it is a concrete manifestation of those behaviors?
If this is the case, then what about the distinction between an abstract data type (ADT) and a data type? Are they truly distinct, or is ADT just colloquially shortened to 'data type'?
I ask this because it has seemed to me that these terms are often used interchangeably in conversation, and it made me wonder if my understanding was incorrect.
I am fairly new to answering on stackoverflow and to this sort of data structure vs data types discussion, but hopefully this helps. These links have done a lot for me in addition to what I've been taught:
Is there a difference between 'data structure' and 'data type'?
Explain the difference between a data *structure* and a data *type*
http://cs.lmu.edu/~ray/notes/dtds/
First of all, I'm going to define my usage of the word "implementation" since it seems I might be using it slightly differently than you are. I define implementation like the implementation files in C++. Such implementation contains the source code for how some interface works. For example the implementation of a singly linked list is a bunch of nodes that each contain data with a starting node that points to the next node until the last node points to some sort of null. In that sense, I can't quite say that a data type is a physical implementation of a data structure. A simplified version is that a data structure is actually the physical implementation of one or more data types. For example, a stack is a data type while a LinkedStack is a data structure that implements a stack. Although a data type can represent all possible instances of a data structure as described by the links above, not all data types have to. For example, an int is a data type, but it's not exactly the best idea to say it is a data structure.
To summarize each, please let me go in the order of data types, abstract data types, and then data structures.
Data types or types for short classify data by its values and operations. For example, if the data is 42, is 42 an int or a string? If it's an int, what int is it (what's its value)? Is it positive or negative? What kinds of operations does it have? Can I divide with it? In that sense, data types depend purely on their external behavior.
Now some data types might not specify any sort of implementation and those data types are called abstract data types. Basically, a data type is an abstract data type if the user can't access nor care about access to how the values and operations are implemented. For example, ints are abstract data types since a programmer doesn't need to know and might not care to know how ints work or how ints are added. Yet, said programmer can still work with ints, adding away to his/her content. User made data types that don't reveal its implementation would also be abstract data types. Because of this, many data types are abstract data types. In addition, abstract data types can model similar data types and data structures and be implemented by specific data types and data structures as the links above describe.
Finally data structures are ways to efficiently store data, and they are all about the implementations. For example, a singly linked list and a doubly linked list are different data structures because they have different implementations. Single linked lists only go forward whereas double linked lists can go forward and backward. I described the implementation for singly linked lists above while in short a doubly linked list's implementation is the same as a singly linked list's implementation but each node would also have a pointer to each previous node to allow the doubly linked list to go backward. The gist of data structures is that the implementation (how data is organized/stored) of a data structure is how it is distinguished.
If you want an example of the efficiency doubly linked lists have over singly linked lists, these links are nice:
When is doubly linked list more efficient than singly linked list?
https://social.msdn.microsoft.com/Forums/vstudio/en-US/270bebdb-9032-4fc1-97c6-bc017d7e0a45/when-to-use-single-linked-list-and-when-to-use-double-linked-list?forum=csharpgeneral
Otherwise, hope I was of some use and good luck.
Abstract Data Type
Defines contractual agreement for behavior and state management
Abstract Data Types exists only conceptually. They have no concrete existence in the context of a language. This is why Wikipedia refers to it specifically as a mathematical model.
Data Structure
Class level implementation of the contract defined by an abstract data type.
Data Structures exists in the form of the code that comprises your class definition.
Data Type
Concrete instance of a class
Data Types exists in the form of objects created from classes you defined.
Examples
A Priority Queue is an abstract data type which can be implemented with a Binary Heap data structure.
A List is an abstract data type that can be implemented with an array or linked list data struture
TLDR
Abstract Data Type > Data Structure > Data Type
A method of interpreting a bit pattern is called a data type. There are several data types such as binary integers, binary coded decimal, non-negative integers, real numbers and character strings. E.g.: a bit string 00100110 can be interpreted as the number '38' (binary coded decimal).
If we do some specific operation with data structure, then data structure with these specific operation are called Abstract Data Type. It is a tool for specifying logical properties and operation of data types.
Data Structure is the implementation of the abstract operations.
-source: books, google search....
As I know about,for example,in Python,int float boolare data types,they are built-in classes,str list tuple dict set frozensetare data structures,they are also built-in classes,and we can write linked list linked stack linked queue linked deque positional list array stack array queue linked tree linked binary tree binary search tree AVL tree red black tree splay tree hash table priority queueand etc,we can call these data structure,or ADT,in my opinion,data structure/ADT is to organize data,data type is to classify data into int/float/bool/etc
Python built-in list is implemented with dynamic array,Python built-intupleis implemented with static array,Python built-in`dict/set/frozrnset are implemented with hash table
I'm in the middle of writing some Cocoa classes to parse ID3 tags from MP3 files. To make them as easy to use as possible, I'm allowing the option to request a tag by the actual ID3 frame id ("TCON", "TPE1", "TALB", etc.) or an equivalent word/phrase ("genre", "artist", "album", etc.)
To store this data, currently I have a reference class which returns an NSDictionary with the frame id's as keys, and word/phrases as objects. As I need to look up definitions in both directions, currently I have a second method which returns the dictionary 'switched round', so the words/phrases are the keys.
My question is whether there is a better way to represent this data. Ideally there would be something similar to NSDictionary, the difference being that both the keys and the values must be unique, and you could look up both an "objectForKey:" and a "keyForObject:"
I could write a class for this myself, but I may lose some of the efficiency from hash tables as described in the NSDictionary documentation... also I'd rather keep the number of classes as low as possible in the overall implementation.
Any ideas? Cheers.
Funny you should ask this...
Quinn Taylor, the author of the CHDataStructures framework just added a CHBidirectionalDictionary to the framework last week. It allows you to find objects by key, and find keys by object. It's basically a wrapper around two mutable dictionaries, so you're guaranteed the same lookup time as with a regular dictionary.
The only caveat is that both the object and key must both conform to the NSCopying protocol.
I have a table in database which has some columns like year,name and also 12 columns (m1,m2,...,m12) representing months. I would like to map this table into one class using NHibernate, ideally, these 12 mapped columns would look like:
_mappedMonths[] = new double[12];
Has anyone a solution for this ?
If you really want to map the columns directly to an array, as you describe, take a look at the ICompositeUserType interface. You can find an article about custom NHibernate mapping here, and this blog post might be of interest as well.
However, if it is not super important you might consider mapping the columns just as you normally would, but as private/protected properties, and then create a public property in your class that exposes those private/public properties as an array. That would be a simpler and faster solution, but would result in code that is not quite as clean.