self-reference

A bad interaction between self-referential types and bounded wildcards

两盒软妹~` 提交于 2019-12-06 00:44:13
This case seems to be another one where Eclipse's Java compiler crushes javac. The only question for me is whether it's a bug in JLS or javac. interface EndoFunctor< C, FC extends EndoFunctor< C, FC > > { /*...*/ } interface Algebra< C, FC extends EndoFunctor< ? extends C, FC > > { /*...*/ } The second line compiles in Eclipse, but fails to compile in javac with the message that "type parameter FC is not within its bound". FC is declared to extend EndoFunctor< ? extends C, FC >, and the bound on FC is that it extend EndoFunctor< D, FC > for the inferred D, which in this case is ? extends C. I

How would you model contact list with self-reference and category?

落爺英雄遲暮 提交于 2019-12-05 23:28:40
Wrestling my head to model following User has many Contact categories (family/friends) One Contact category has many contacts One contact can be in one or more contact categories. I end up with following, but I still believe, there must be better solution outhere. class User < ActiveRecord::Base has_many :contact_groups def get_all_contacts self.contact_groups.each do |group| contacts << group.users end end class ContactGroup < ActiveRecord::Base has_and_belongs_to_many :users end Assumptions This is a system for many users, not just one, so you need to specify the Owner on the Contact and

How to define a one to one self reference using Entity Framework Code First

时光总嘲笑我的痴心妄想 提交于 2019-12-05 18:06:18
I want to implement versioning on my entity Stuff . Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity framework 6, code first. I tried with the following model and modelbuilder statement (and many variations). public class Stuff { public int StuffId { get; set; } [ForeignKey("NextVersion")] public int? NextVersionId { get; set; } [InverseProperty("PreviousVersion")] public virtual Stuff NextVersion { get; set; } public virtual Stuff PreviousVersion {

Advice/discussion on anonymous “self referential” data structures

℡╲_俬逩灬. 提交于 2019-12-05 03:47:05
Apologies for any mistaken terminology--I'm quite new to computer science, and I pretty much only know Clojure (but I guess I'd say I know it pretty well). So, I haven't done a ton of research on this, but I've sometimes found it useful when writing Clojure code to be able to refer to some "intermediate version of whatever data structure I'm in" from within that data structure (a lot like in a let ). Quick examples: => (self-ish {:a 10 :b (inc (this :a)) :c (count (vals this))}) => {:a 10, :b 11, :c 3} => (self-ish ["a" "b" (reduce str this)]) => ["a" "b" "ab"] //Works in any nested bits too =

Self referential type

房东的猫 提交于 2019-12-05 03:18:35
问题 What type T makes the following code compilable? T f(){ return &f; } I'd prefer a C answer, but I marked the question as C and C++ in case there is only an answer using templates. 回答1: I hope this isn't cheating (C++ only): class T { private: T (*_func)(); public: T(T (*func)()) : _func(func) {} T operator()() { return *this; } }; T f() { return &f; } int main() { f()()()()()()()(); } 回答2: Interesting problem, but without acceptable C solution, I guess. Why this is impossible with C ? (some

Recursive reference to a list within itself [duplicate]

痞子三分冷 提交于 2019-12-05 01:06:12
This question already has answers here : Why does list(my_list) modify the object? (2 answers) Closed 5 years ago . So I came across something very weird in python. I tried adding a reference to the list to itself. The code might help demonstrate what I am saying better than I can express. I am using IDLE editor(interactive mode). >>>l=[1,2,3] >>>l.append(l) >>>print(l) [1,2,3,[...]] >>>del l[:-1] >>>print(l) [[...]] So far the output is as expected. But when I do this. y=l[:] print(y) To me it seems that the output should be [[...]] But it is [[[...]]] Apparently instead of creating a copy of

copy constructor of a class which has self-pointer to itself in C++?

懵懂的女人 提交于 2019-12-04 18:39:34
I wanted to ask that how will we implement a copy constructor of a class which has self pointer to itself as its data member, i want to implement a deep copy, class City { string name; City* parent; public: City(string nam, double dcov); City(string nam, double dcov, City* c); City(const City& obj) { this-> name = obj.name; // how to assign parent parent = new City(??) } ~City(); void setName(string name1); void setDistanceCovered(int dist); string getName(); double getDistanceCovered(); City* getParent(){return parent;} }; I am confused that this line // how to assign parent parent = new City

Convert from self-reference array into nested array in tree

别说谁变了你拦得住时间么 提交于 2019-12-04 17:17:40
I use angular-bootstrap-nav-tree I have Array that i get from self-reference table Like this: var obj = [ {id:1,label:"Animal"}, {id:2,label:"Vigitable"}, {id:3,label:"Cats",parent:1}, {id:4,label:"black cat",parent:3}, {id:5,label:"orange",parent:2}, ]; I want to convert it to be nested like this: var convrted = [ {id:1,label:"Animal",children[ {id:3,label:"Cats",parent:1,children[{id:4,label:"black cat",parent:3}]} ]}, {id:2,label:"Vigitable",children[ {id:5,label:"orange",parent:2} ]} ]; I want it to work unlimited levels dynamic. This will do the job: function nest (array) { nested = [];

Self referencing entity & insert order - using Entity Framework Code First

谁说我不能喝 提交于 2019-12-04 16:05:03
I have two entities looking like this: public class AssetSession { [Key] public Guid Id { get; set; } public string RoomNumber { get; set; } public Contact Contact { get; set; } public virtual List<Asset> Assets { get; set; } } public class Asset { [Key] public Guid Id { get; set; } public Guid? ParentId { get; set; } [ForeignKey("ParentId")] public Asset Parent { get; set; } public string Barcode { get; set; } public string SerialNumber { get; set; } public Guid AssetSessionId { get; set; } [ForeignKey("AssetSessionId")] public AssetSession AssetSession { get; set; } } protected override void

Fluent NHibernate Self Referencing Many To Many

情到浓时终转凉″ 提交于 2019-12-04 10:38:15
问题 I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship HasManyToMany(x => x.RelatedBooks) .ParentKeyColumn("BookId") .ChildKeyColumn("RelatedBookId") .Table("RelatedBooks") .Cascade.SaveUpdate(); Here is a sample of the data that