For faster navigation, this Iframe is preloading the Wikiwand page for آرایه انجمنی.

آرایه انجمنی

در علوم رایانه، آرایهٔ ربطی، نگاشت، یا دیکشنری به نوع داده انتزاعی گفته می‌شود که از کلکسیونی از جفت‌های (کلید، مقدار) تشکیل شده‌است، بطوری‌که هر کلید ممکن حداکثر یکبار در کلکسیون ظاهر می‌شود. دلیل این نامگذاری این است که در این نوع آرایه هر مقدار به صراحت به یک کلید «ربط» داده شده‌است (در انگلیسی: Associated) در حالیکه در نوع عادی آرایه، ربط دهی به صورت ضمنی انجام می‌شود؛ یعنی هر مقدار به‌طور ضمنی مرتبط با یک اندیس (در انگلیسی: Index) است و نیازی به ذخیرهٔ کلید (اندیس) وجود ندارد. به دلیل صریح بودن ربط دهی در این نوع آرایه، آن را آرایهٔ «ربطی» (به انگلیسی Associative Array) می‌نامند، که برخی آن را آرایهٔ انجمنی نیز ترجمه کرده‌اند.

عملیات مرتبط با این نوع داده عبارتند از:[۱][۲]

  • افزودن جفت به کلکسیون،
  • حذف جفت از کلکسیون،
  • تغییر مقدار جفت‌های موجود،
  • مراجعه به مقدار مرتبط با یک کلید خاص

مثال

[ویرایش]

در زبان برنامه‌نویسی پایتون آرایه‌های انجمنی را می‌توان با قرار دادن جفت‌های key: value جدا شده با کاما در داخل آکلاد ایجاد کرد:[۳]

a = {'name': 'john', 'age': 28}

در زبان برنامه‌نویسی پی‌اچ‌پی آرایه‌های انجمنی را می‌توان به کمک دستور array یا دستور کوتاه array (با کمک کروشه) در زمان تعریف آرایه ثبت یا پس از تعریف آرایه کلیدهای جدید به آن اضافه کرد:

$a = array("name"=>"Masoud", "age"=>24);

$c = array();
$c["name"] = "Masoud";
$c["age"] = 24;

$b = ["name"=>"Masoud", "age"=>24];

$d = [];
$d["name"] = "Masoud";
$d["age"] = 24;

if($a == $b == $c == $d)
{
    if($a['name'] == $b['name'] == $c['name'] == $d['name'])
    {
        if($a['age'] == $b['age'] == $c['age'] == $d['age'])
        {
            print('$a, $b, $c and $d are equal');
        }
    }
}

در مثال بالا، پس از اجرای نمونه کد پی‌اچ‌پی، هر چهار متغیر a$ و b$ و c$ و d$ دارای مقادیر برابر خواهند بود و مقدار a, $b, $c and $d are equal$ چاپ خواهد شد.

پانویس

[ویرایش]
  1. Goodrich, Michael T.; Tamassia, Roberto (2006), "9.1 The Map Abstract Data Type", Data Structures & Algorithms in Java (4th ed.), Wiley, pp. 368–371.
  2. Mehlhorn, Kurt; Sanders, Peter (2008), "4 Hash Tables and Associative Arrays", Algorithms and Data Structures: The Basic Toolbox, Springer, pp. 81–98.
  3. مستندات پایتون - انواع داده توکار - دیکشنری
{{bottomLinkPreText}} {{bottomLinkText}}
آرایه انجمنی
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?